mirror of
https://github.com/YunoHost-Apps/nomad_ynh.git
synced 2024-09-03 19:55:53 +02:00
LXC driver
This commit is contained in:
parent
ba83dc8281
commit
700cb2ac75
7 changed files with 139 additions and 65 deletions
|
@ -6,6 +6,7 @@
|
|||
bootstrap_expect="1"
|
||||
retry_join="192.168.1.100"
|
||||
server_ip="192.168.1.100"
|
||||
driver_lxc=1
|
||||
; Checks
|
||||
pkg_linter=1
|
||||
setup_sub_dir=0
|
||||
|
@ -27,6 +28,7 @@
|
|||
bootstrap_expect="1"
|
||||
retry_join="192.168.1.100"
|
||||
server_ip="none..."
|
||||
driver_lxc=1
|
||||
; Checks
|
||||
pkg_linter=1
|
||||
setup_sub_dir=0
|
||||
|
|
|
@ -74,6 +74,26 @@
|
|||
},
|
||||
"example": "192.168.1.100",
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"name": "server_ip",
|
||||
"type": "string",
|
||||
"ask": {
|
||||
"en": "[Client only] What is the IP of the Nomad server node ?"
|
||||
},
|
||||
"example": "192.168.1.100",
|
||||
"optional": true
|
||||
},
|
||||
{
|
||||
"name": "driver_lxc",
|
||||
"type": "boolean",
|
||||
"ask": {
|
||||
"en": "[Client only] Do you want to install LXC driver ?"
|
||||
},
|
||||
"default": true,
|
||||
"help": {
|
||||
"en": "It will also install lxc."
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -7,7 +7,10 @@
|
|||
# dependencies used by the app
|
||||
pkg_dependencies="nomad"
|
||||
|
||||
client_pkg_dependencies="pkg-config lxc-dev lxc lxc-templates"
|
||||
server_pkg_dependencies=""
|
||||
|
||||
client_pkg_dependencies=""
|
||||
client_lxc_pkg_dependencies="pkg-config lxc-dev lxc lxc-templates"
|
||||
|
||||
go_version=1.15
|
||||
|
||||
|
|
|
@ -31,6 +31,7 @@ node_type=$YNH_APP_ARG_NODE_TYPE
|
|||
bootstrap_expect=$YNH_APP_ARG_BOOTSTRAP_EXPECT
|
||||
retry_join=$YNH_APP_ARG_RETRY_JOIN
|
||||
server_ip=$YNH_APP_ARG_SERVER_IP
|
||||
driver_lxc=$YNH_APP_ARG_DRIVER_LXC
|
||||
|
||||
app=$YNH_APP_INSTANCE_NAME
|
||||
|
||||
|
@ -57,6 +58,7 @@ ynh_app_setting_set --app=$app --key=node_type --value=$node_type
|
|||
ynh_app_setting_set --app=$app --key=bootstrap_expect --value=$bootstrap_expect
|
||||
ynh_app_setting_set --app=$app --key=retry_join --value=$retry_join
|
||||
ynh_app_setting_set --app=$app --key=server_ip --value=$server_ip
|
||||
ynh_app_setting_set --app=$app --key=driver_lxc --value=$driver_lxc
|
||||
ynh_app_setting_set --app=$app --key=lxc_bridge --value=$lxc_bridge
|
||||
ynh_app_setting_set --app=$app --key=plage_ip --value=$plage_ip
|
||||
ynh_app_setting_set --app=$app --key=main_iface --value=$main_iface
|
||||
|
@ -96,10 +98,19 @@ fi
|
|||
#=================================================
|
||||
ynh_script_progression --message="Installing dependencies..."
|
||||
|
||||
if [ "$node_type" == "server" ]
|
||||
then
|
||||
ynh_install_app_dependencies $server_pkg_dependencies
|
||||
fi
|
||||
|
||||
if [ "$node_type" == "client" ]
|
||||
then
|
||||
if [ $driver_lxc -eq 1 ]
|
||||
then
|
||||
$client_pkg_dependencies="$client_pkg_dependencies $client_lxc_pkg_dependencies"
|
||||
ynh_install_go --go_version=$go_version
|
||||
fi
|
||||
ynh_install_app_dependencies $client_pkg_dependencies
|
||||
ynh_install_go --go_version=$go_version
|
||||
fi
|
||||
ynh_install_extra_app_dependencies --repo="deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" --package="$pkg_dependencies" --key="https://apt.releases.hashicorp.com/gpg"
|
||||
|
||||
|
@ -137,27 +148,30 @@ chmod -R o-rwx "$datadir"
|
|||
chown -R $app:$app "$datadir"
|
||||
|
||||
#=================================================
|
||||
# BUILD LXC DRIVER
|
||||
# BUILD DRIVERS
|
||||
#=================================================
|
||||
|
||||
if [ "$node_type" == "client" ]
|
||||
then
|
||||
ynh_script_progression --message="Building LXC driver..."
|
||||
if [ $driver_lxc -eq 1 ]
|
||||
then
|
||||
ynh_script_progression --message="Building LXC driver..."
|
||||
|
||||
tempdir="$(mktemp -d)"
|
||||
ynh_setup_source --dest_dir="$tempdir" --source_id="driver-lxc"
|
||||
tempdir="$(mktemp -d)"
|
||||
ynh_setup_source --dest_dir="$tempdir" --source_id="driver-lxc"
|
||||
|
||||
pushd $tempdir
|
||||
final_path=$tempdir
|
||||
ynh_use_go
|
||||
export GOPATH="$tempdir/go"
|
||||
export GOCACHE="$tempdir/.cache"
|
||||
ynh_exec_warn_less $ynh_go build
|
||||
popd
|
||||
pushd $tempdir
|
||||
final_path=$tempdir
|
||||
ynh_use_go
|
||||
export GOPATH="$tempdir/go"
|
||||
export GOCACHE="$tempdir/.cache"
|
||||
ynh_exec_warn_less $ynh_go build
|
||||
popd
|
||||
|
||||
mv -f $tempdir/nomad-driver-lxc $datadir/plugins/nomad-driver-lxc
|
||||
mv -f $tempdir/nomad-driver-lxc $datadir/plugins/nomad-driver-lxc
|
||||
|
||||
ynh_secure_remove --file="$tempdir"
|
||||
ynh_secure_remove --file="$tempdir"
|
||||
fi
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
@ -189,20 +203,23 @@ then
|
|||
ynh_add_config --template="../conf/client.hcl" --destination="$config_path/client.hcl"
|
||||
chmod 400 "$config_path/client.hcl"
|
||||
chown $app:$app "$config_path/client.hcl"
|
||||
|
||||
if [ $driver_lxc -eq 1 ]
|
||||
then
|
||||
ynh_add_config --template="../conf/driver-lxc.hcl" --destination="$config_path/driver-lxc.hcl"
|
||||
chmod 400 "$config_path/driver-lxc.hcl"
|
||||
chown $app:$app "$config_path/driver-lxc.hcl"
|
||||
|
||||
ynh_add_config --template="../conf/driver-lxc.hcl" --destination="$config_path/driver-lxc.hcl"
|
||||
chmod 400 "$config_path/driver-lxc.hcl"
|
||||
chown $app:$app "$config_path/driver-lxc.hcl"
|
||||
ynh_add_config --template="../conf/dnsmasq-lxd" --destination="/etc/dnsmasq.d/lxd"
|
||||
systemctl restart dnsmasq
|
||||
|
||||
ynh_add_config --template="../conf/dnsmasq-lxd" --destination="/etc/dnsmasq.d/lxd"
|
||||
systemctl restart dnsmasq
|
||||
|
||||
if [ ! ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
|
||||
ynh_add_config --template="../conf/lxc-net" --destination="/etc/default/lxc-net"
|
||||
if [ ! ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
|
||||
ynh_add_config --template="../conf/lxc-net" --destination="/etc/default/lxc-net"
|
||||
fi
|
||||
ynh_add_config --template="../conf/default.conf" --destination="/etc/lxc/default.conf"
|
||||
systemctl enable lxc-net --quiet
|
||||
ynh_systemd_action --service_name=lxc-net --action="restart" --line_match="Started LXC network bridge" --log_path="systemd"
|
||||
fi
|
||||
ynh_add_config --template="../conf/default.conf" --destination="/etc/lxc/default.conf"
|
||||
systemctl enable lxc-net --quiet
|
||||
ynh_systemd_action --service_name=lxc-net --action="restart" --line_match="Started LXC network bridge" --log_path="systemd"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -20,6 +20,7 @@ domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|||
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
|
||||
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
||||
node_type=$(ynh_app_setting_get --app=$app --key=node_type)
|
||||
driver_lxc=$(ynh_app_setting_get --app=$app --key=driver_lxc)
|
||||
rpc_port=$(ynh_app_setting_get --app=$app --key=rpc_port)
|
||||
serf_port=$(ynh_app_setting_get --app=$app --key=serf_port)
|
||||
|
||||
|
@ -79,15 +80,18 @@ fi
|
|||
|
||||
if [ "$node_type" == "client" ]
|
||||
then
|
||||
|
||||
if [ $driver_lxc -eq 1 ]
|
||||
then
|
||||
lxc_bridge=$(ynh_app_setting_get --app=$app --key=lxc_bridge)
|
||||
|
||||
lxc_bridge=$(ynh_app_setting_get --app=$app --key=lxc_bridge)
|
||||
|
||||
ynh_systemd_action --service_name=lxc-net --action="stop"
|
||||
systemctl disable lxc-net --quiet
|
||||
ynh_secure_remove --file="/etc/default/lxc-net"
|
||||
ynh_secure_remove --file="/etc/lxc/default.conf"
|
||||
ynh_secure_remove --file="/etc/dnsmasq.d/lxd"
|
||||
systemctl restart dnsmasq
|
||||
ynh_systemd_action --service_name=lxc-net --action="stop"
|
||||
systemctl disable lxc-net --quiet
|
||||
ynh_secure_remove --file="/etc/default/lxc-net"
|
||||
ynh_secure_remove --file="/etc/lxc/default.conf"
|
||||
ynh_secure_remove --file="/etc/dnsmasq.d/lxd"
|
||||
systemctl restart dnsmasq
|
||||
fi
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -32,6 +32,7 @@ path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|||
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
|
||||
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
||||
node_type=$(ynh_app_setting_get --app=$app --key=node_type)
|
||||
driver_lxc=$(ynh_app_setting_get --app=$app --key=driver_lxc)
|
||||
http_port=$(ynh_app_setting_get --app=$app --key=http_port)
|
||||
rpc_port=$(ynh_app_setting_get --app=$app --key=rpc_port)
|
||||
serf_port=$(ynh_app_setting_get --app=$app --key=serf_port)
|
||||
|
@ -71,8 +72,17 @@ chown -R $app:$app "$datadir"
|
|||
#=================================================
|
||||
ynh_script_progression --message="Reinstalling dependencies..."
|
||||
|
||||
if [ "$node_type" == "server" ]
|
||||
then
|
||||
ynh_install_app_dependencies $server_pkg_dependencies
|
||||
fi
|
||||
|
||||
if [ "$node_type" == "client" ]
|
||||
then
|
||||
if [ $driver_lxc -eq 1 ]
|
||||
then
|
||||
$client_pkg_dependencies="$client_pkg_dependencies $client_lxc_pkg_dependencies"
|
||||
fi
|
||||
ynh_install_app_dependencies $client_pkg_dependencies
|
||||
fi
|
||||
ynh_install_extra_app_dependencies --repo="deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" --package="$pkg_dependencies" --key="https://apt.releases.hashicorp.com/gpg"
|
||||
|
@ -106,22 +116,24 @@ then
|
|||
fi
|
||||
|
||||
if [ "$node_type" == "client" ]
|
||||
then
|
||||
then
|
||||
if [ $driver_lxc -eq 1 ]
|
||||
then
|
||||
lxc_bridge=$(ynh_app_setting_get --app=$app --key=lxc_bridge)
|
||||
plage_ip=$(ynh_app_setting_get --app=$app --key=plage_ip)
|
||||
main_iface=$(ip route | grep default | awk '{print $5;}')
|
||||
ynh_app_setting_set --app=$app --key=main_iface --value=$main_iface
|
||||
|
||||
lxc_bridge=$(ynh_app_setting_get --app=$app --key=lxc_bridge)
|
||||
plage_ip=$(ynh_app_setting_get --app=$app --key=plage_ip)
|
||||
main_iface=$(ip route | grep default | awk '{print $5;}')
|
||||
ynh_app_setting_set --app=$app --key=main_iface --value=$main_iface
|
||||
ynh_add_config --template="../conf/dnsmasq-lxd" --destination="/etc/dnsmasq.d/lxd"
|
||||
systemctl restart dnsmasq
|
||||
|
||||
ynh_add_config --template="../conf/dnsmasq-lxd" --destination="/etc/dnsmasq.d/lxd"
|
||||
systemctl restart dnsmasq
|
||||
|
||||
if [ ! ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
|
||||
ynh_add_config --template="../conf/lxc-net" --destination="/etc/default/lxc-net"
|
||||
if [ ! ${PACKAGE_CHECK_EXEC:-0} -eq 1 ]; then
|
||||
ynh_add_config --template="../conf/lxc-net" --destination="/etc/default/lxc-net"
|
||||
fi
|
||||
ynh_add_config --template="../conf/default.conf" --destination="/etc/lxc/default.conf"
|
||||
systemctl enable lxc-net --quiet
|
||||
ynh_systemd_action --service_name=lxc-net --action="restart" --line_match="Started LXC network bridge" --log_path="systemd"
|
||||
fi
|
||||
ynh_add_config --template="../conf/default.conf" --destination="/etc/lxc/default.conf"
|
||||
systemctl enable lxc-net --quiet
|
||||
ynh_systemd_action --service_name=lxc-net --action="restart" --line_match="Started LXC network bridge" --log_path="systemd"
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
|
|
@ -25,6 +25,7 @@ node_type=$(ynh_app_setting_get --app=$app --key=node_type)
|
|||
bootstrap_expect=$(ynh_app_setting_get --app=$app --key=bootstrap_expect)
|
||||
retry_join=$(ynh_app_setting_get --app=$app --key=retry_join)
|
||||
server_ip=$(ynh_app_setting_get --app=$app --key=server_ip)
|
||||
driver_lxc=$(ynh_app_setting_get --app=$app --key=driver_lxc)
|
||||
http_port=$(ynh_app_setting_get --app=$app --key=http_port)
|
||||
rpc_port=$(ynh_app_setting_get --app=$app --key=rpc_port)
|
||||
serf_port=$(ynh_app_setting_get --app=$app --key=serf_port)
|
||||
|
@ -85,10 +86,19 @@ ynh_system_user_create --username=$app
|
|||
#=================================================
|
||||
ynh_script_progression --message="Upgrading dependencies..."
|
||||
|
||||
if [ "$node_type" == "server" ]
|
||||
then
|
||||
ynh_install_app_dependencies $server_pkg_dependencies
|
||||
fi
|
||||
|
||||
if [ "$node_type" == "client" ]
|
||||
then
|
||||
if [ $driver_lxc -eq 1 ]
|
||||
then
|
||||
$client_pkg_dependencies="$client_pkg_dependencies $client_lxc_pkg_dependencies"
|
||||
ynh_install_go --go_version=$go_version
|
||||
fi
|
||||
ynh_install_app_dependencies $client_pkg_dependencies
|
||||
ynh_install_go --go_version=$go_version
|
||||
fi
|
||||
ynh_install_extra_app_dependencies --repo="deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" --package="$pkg_dependencies" --key="https://apt.releases.hashicorp.com/gpg"
|
||||
|
||||
|
@ -103,27 +113,30 @@ ynh_add_nginx_config
|
|||
#=================================================
|
||||
# SPECIFIC UPGRADE
|
||||
#=================================================
|
||||
# BUILD LXC DRIVER
|
||||
# BUILD DRIVERS
|
||||
#=================================================
|
||||
|
||||
if [ "$node_type" == "client" ]
|
||||
then
|
||||
ynh_script_progression --message="Building LXC driver..."
|
||||
if [ $driver_lxc -eq 1 ]
|
||||
then
|
||||
ynh_script_progression --message="Building LXC driver..."
|
||||
|
||||
tempdir="$(mktemp -d)"
|
||||
ynh_setup_source --dest_dir="$tempdir" --source_id="driver-lxc"
|
||||
tempdir="$(mktemp -d)"
|
||||
ynh_setup_source --dest_dir="$tempdir" --source_id="driver-lxc"
|
||||
|
||||
pushd $tempdir
|
||||
final_path=$tempdir
|
||||
ynh_use_go
|
||||
export GOPATH="$tempdir/go"
|
||||
export GOCACHE="$tempdir/.cache"
|
||||
ynh_exec_warn_less$ynh_go build
|
||||
popd
|
||||
pushd $tempdir
|
||||
final_path=$tempdir
|
||||
ynh_use_go
|
||||
export GOPATH="$tempdir/go"
|
||||
export GOCACHE="$tempdir/.cache"
|
||||
ynh_exec_warn_less$ynh_go build
|
||||
popd
|
||||
|
||||
mv -f $tempdir/nomad-driver-lxc $datadir/plugins/nomad-driver-lxc
|
||||
mv -f $tempdir/nomad-driver-lxc $datadir/plugins/nomad-driver-lxc
|
||||
|
||||
ynh_secure_remove --file="$tempdir"
|
||||
ynh_secure_remove --file="$tempdir"
|
||||
fi
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
@ -152,10 +165,13 @@ then
|
|||
ynh_add_config --template="../conf/client.hcl" --destination="$config_path/client.hcl"
|
||||
chmod 400 "$config_path/client.hcl"
|
||||
chown $app:$app "$config_path/client.hcl"
|
||||
|
||||
ynh_add_config --template="../conf/driver-lxc.hcl" --destination="$config_path/driver-lxc.hcl"
|
||||
chmod 400 "$config_path/driver-lxc.hcl"
|
||||
chown $app:$app "$config_path/driver-lxc.hcl"
|
||||
|
||||
if [ $driver_lxc -eq 1 ]
|
||||
then
|
||||
ynh_add_config --template="../conf/driver-lxc.hcl" --destination="$config_path/driver-lxc.hcl"
|
||||
chmod 400 "$config_path/driver-lxc.hcl"
|
||||
chown $app:$app "$config_path/driver-lxc.hcl"
|
||||
fi
|
||||
fi
|
||||
|
||||
#=================================================
|
||||
|
|
Loading…
Reference in a new issue