1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/nomad_ynh.git synced 2024-09-03 19:55:53 +02:00

Merge pull request #3 from YunoHost-Apps/improving

Some improvements
This commit is contained in:
yalh76 2022-07-23 17:59:05 +02:00 committed by GitHub
commit 1c7f266b97
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 200 additions and 88 deletions

View file

@ -3,7 +3,10 @@
domain="domain.tld"
is_public=1
node_type="client"
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
@ -22,7 +25,10 @@
domain="domain.tld"
is_public=1
node_type="server"
bootstrap_expect="1"
retry_join="192.168.1.100"
server_ip="none..."
driver_lxc=1
; Checks
pkg_linter=1
setup_sub_dir=0

View file

@ -1,5 +1,5 @@
lxc.net.0.type = veth
lxc.net.0.link = __LXC_BRIDGE__
lxc.net.0.link = __CLIENT_LXC_BRIDGE__
lxc.net.0.flags = up
lxc.net.0.hwaddr = 00:16:3e:xx:xx:xx
lxc.apparmor.profile = generated

View file

@ -1,2 +1,2 @@
bind-interfaces
except-interface=__LXC_BRIDGE__
except-interface=__CLIENT_LXC_BRIDGE__

View file

@ -1,9 +1,9 @@
USE_LXC_BRIDGE="true"
LXC_BRIDGE="__LXC_BRIDGE__"
LXC_ADDR="__PLAGE_IP__.1"
LXC_BRIDGE="__CLIENT_LXC_BRIDGE__"
LXC_ADDR="__CLIENT_LXC_PLAGE_IP__.1"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="__PLAGE_IP__.0/24"
LXC_DHCP_RANGE="__PLAGE_IP__.2,__PLAGE_IP__.254"
LXC_NETWORK="__CLIENT_LXC_PLAGE_IP__.0/24"
LXC_DHCP_RANGE="__CLIENT_LXC_PLAGE_IP__.2,__CLIENT_LXC_PLAGE_IP__.254"
LXC_DHCP_MAX="253"
LXC_DHCP_CONFILE=""
LXC_DOMAIN=""

View file

@ -8,7 +8,7 @@ server {
# This is an integer representing the number of server nodes to wait for before bootstrapping. It is most
# common to use the odd-numbered integers 3 or 5 for this value, depending on the cluster size. A value of
# 1 does not provide any fault tolerance and is not recommended for production use cases.
bootstrap_expect = 1
bootstrap_expect = __BOOTSTRAP_EXPECT__
# This is the data directory used for server-specific data, including the replicated log. By default, this
# directory lives inside of the data_dir in the "server" sub-path.
@ -38,7 +38,7 @@ server {
# Similar to start_join but allows retrying a join if the first attempt fails. This is useful for cases
# where we know the address will become available eventually.
# retry_join = []
retry_join = ["__RETRY_JOIN__"]
# The time to wait between join attempts. Defaults to 30s.
retry_interval = "30s"

View file

@ -45,6 +45,27 @@
"choices": ["server", "client"],
"default": "server"
},
{
"name": "bootstrap_expect",
"type": "string",
"ask": {
"en": "[Server only] How many server nodes to wait for before bootstrapping ?"
},
"choices": ["1", "3", "5", "7", "9"],
"default": "1",
"help": {
"en": "For production, it's recommanded to have 3 to 5 server nodes."
}
},
{
"name": "retry_join",
"type": "string",
"ask": {
"en": "[Server only] What is the IP of another server to join ?"
},
"example": "192.168.1.100",
"optional": true
},
{
"name": "server_ip",
"type": "string",
@ -53,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."
}
}
]
}

View file

@ -5,9 +5,13 @@
#=================================================
# dependencies used by the app
pkg_dependencies="nomad"
pkg_dependencies=""
extra_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

40
scripts/install Executable file → Normal file
View file

@ -28,13 +28,16 @@ domain=$YNH_APP_ARG_DOMAIN
path_url="/"
is_public=$YNH_APP_ARG_IS_PUBLIC
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
lxc_bridge="lxcbr0"
plage_ip="10.1.44"
main_iface=$(ip route | grep default | awk '{print $5;}')
client_lxc_bridge="lxcbr0"
client_lxc_plage_ip="10.1.44"
client_lxc_main_iface=$(ip route | grep default | awk '{print $5;}')
#=================================================
# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS
@ -52,10 +55,13 @@ ynh_script_progression --message="Storing installation settings..."
ynh_app_setting_set --app=$app --key=domain --value=$domain
ynh_app_setting_set --app=$app --key=path --value=$path_url
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=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
ynh_app_setting_set --app=$app --key=driver_lxc --value=$driver_lxc
ynh_app_setting_set --app=$app --key=client_lxc_bridge --value=$client_lxc_bridge
ynh_app_setting_set --app=$app --key=client_lxc_plage_ip --value=$client_lxc_plage_ip
ynh_app_setting_set --app=$app --key=client_lxc_main_iface --value=$client_lxc_main_iface
#=================================================
# STANDARD MODIFICATIONS
@ -92,12 +98,22 @@ fi
#=================================================
ynh_script_progression --message="Installing dependencies..."
if [ "$node_type" == "server" ]
then
pkg_dependencies="$pkg_dependencies $server_pkg_dependencies"
fi
if [ "$node_type" == "client" ]
then
ynh_install_app_dependencies $client_pkg_dependencies
if [ $driver_lxc -eq 1 ]
then
client_pkg_dependencies="$client_pkg_dependencies $client_lxc_pkg_dependencies"
ynh_exec_warn_less ynh_install_go --go_version=$go_version
fi
pkg_dependencies="$pkg_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"
ynh_install_app_dependencies $pkg_dependencies
ynh_install_extra_app_dependencies --repo="deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" --package="$extra_pkg_dependencies" --key="https://apt.releases.hashicorp.com/gpg"
#=================================================
# CREATE DEDICATED USER
@ -133,11 +149,13 @@ chmod -R o-rwx "$datadir"
chown -R $app:$app "$datadir"
#=================================================
# BUILD LXC DRIVER
# BUILD DRIVERS
#=================================================
if [ "$node_type" == "client" ]
then
if [ $driver_lxc -eq 1 ]
then
ynh_script_progression --message="Building LXC driver..."
tempdir="$(mktemp -d)"
@ -154,6 +172,7 @@ then
mv -f $tempdir/nomad-driver-lxc $datadir/plugins/nomad-driver-lxc
ynh_secure_remove --file="$tempdir"
fi
fi
#=================================================
@ -186,6 +205,8 @@ then
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"
@ -199,6 +220,7 @@ then
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
fi
#=================================================

View file

@ -21,6 +21,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)
@ -81,7 +82,9 @@ fi
if [ "$node_type" == "client" ]
then
lxc_bridge=$(ynh_app_setting_get --app=$app --key=lxc_bridge)
if [ $driver_lxc -eq 1 ]
then
client_lxc_bridge=$(ynh_app_setting_get --app=$app --key=client_lxc_bridge)
ynh_systemd_action --service_name=lxc-net --action="stop"
systemctl disable lxc-net --quiet
@ -89,6 +92,7 @@ then
ynh_secure_remove --file="/etc/lxc/default.conf"
ynh_secure_remove --file="/etc/dnsmasq.d/lxd"
systemctl restart dnsmasq
fi
fi
#=================================================
@ -100,7 +104,10 @@ ynh_script_progression --message="Removing dependencies..."
ynh_remove_app_dependencies
if [ "$node_type" == "client" ]
then
if [ $driver_lxc -eq 1 ]
then
ynh_remove_go
fi
fi
#=================================================

27
scripts/restore Executable file → Normal file
View file

@ -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,11 +72,21 @@ chown -R $app:$app "$datadir"
#=================================================
ynh_script_progression --message="Reinstalling dependencies..."
if [ "$node_type" == "server" ]
then
pkg_dependencies="$pkg_dependencies $server_pkg_dependencies"
fi
if [ "$node_type" == "client" ]
then
ynh_install_app_dependencies $client_pkg_dependencies
if [ $driver_lxc -eq 1 ]
then
client_pkg_dependencies="$client_pkg_dependencies $client_lxc_pkg_dependencies"
fi
pkg_dependencies="$pkg_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"
ynh_install_app_dependencies $pkg_dependencies
ynh_install_extra_app_dependencies --repo="deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" --package="$extra_pkg_dependencies" --key="https://apt.releases.hashicorp.com/gpg"
#=================================================
# RESTORE THE NGINX CONFIGURATION
@ -107,11 +118,12 @@ fi
if [ "$node_type" == "client" ]
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
if [ $driver_lxc -eq 1 ]
then
client_lxc_bridge=$(ynh_app_setting_get --app=$app --key=client_lxc_bridge)
client_lxc_plage_ip=$(ynh_app_setting_get --app=$app --key=client_lxc_plage_ip)
client_lxc_main_iface=$(ip route | grep default | awk '{print $5;}')
ynh_app_setting_set --app=$app --key=client_lxc_main_iface --value=$client_lxc_main_iface
ynh_add_config --template="../conf/dnsmasq-lxd" --destination="/etc/dnsmasq.d/lxd"
systemctl restart dnsmasq
@ -123,6 +135,7 @@ then
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
fi
#=================================================

View file

@ -22,7 +22,10 @@ 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)
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)
@ -83,12 +86,22 @@ ynh_system_user_create --username=$app
#=================================================
ynh_script_progression --message="Upgrading dependencies..."
if [ "$node_type" == "server" ]
then
pkg_dependencies="$pkg_dependencies $server_pkg_dependencies"
fi
if [ "$node_type" == "client" ]
then
ynh_install_app_dependencies $client_pkg_dependencies
if [ $driver_lxc -eq 1 ]
then
client_pkg_dependencies="$client_pkg_dependencies $client_lxc_pkg_dependencies"
ynh_exec_warn_less ynh_install_go --go_version=$go_version
fi
pkg_dependencies="$pkg_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"
ynh_install_app_dependencies $pkg_dependencies
ynh_install_extra_app_dependencies --repo="deb https://apt.releases.hashicorp.com $(lsb_release -cs) main" --package="$extra_pkg_dependencies" --key="https://apt.releases.hashicorp.com/gpg"
#=================================================
# NGINX CONFIGURATION
@ -101,11 +114,13 @@ ynh_add_nginx_config
#=================================================
# SPECIFIC UPGRADE
#=================================================
# BUILD LXC DRIVER
# BUILD DRIVERS
#=================================================
if [ "$node_type" == "client" ]
then
if [ $driver_lxc -eq 1 ]
then
ynh_script_progression --message="Building LXC driver..."
tempdir="$(mktemp -d)"
@ -122,6 +137,7 @@ then
mv -f $tempdir/nomad-driver-lxc $datadir/plugins/nomad-driver-lxc
ynh_secure_remove --file="$tempdir"
fi
fi
#=================================================
@ -151,9 +167,12 @@ then
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"
fi
fi
#=================================================