2022-07-20 12:04:29 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STOP SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2024-03-20 11:32:08 +01:00
|
|
|
ynh_script_progression --message="Stopping $app's systemd service..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2024-02-14 14:13:22 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2024-02-14 14:13:22 +01:00
|
|
|
# ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-07-23 04:57:16 +02:00
|
|
|
# BUILD DRIVERS
|
2022-07-20 12:04:29 +02:00
|
|
|
#=================================================
|
2024-02-14 14:13:22 +01:00
|
|
|
if [ "$node_type" == "client" ] && [ "$driver_lxc" -eq 1 ]; then
|
2024-03-20 13:39:38 +01:00
|
|
|
ynh_script_progression --message="Installing Go..."
|
2024-02-14 14:13:22 +01:00
|
|
|
ynh_exec_warn_less ynh_install_go --go_version="$go_version"
|
2024-03-20 13:39:38 +01:00
|
|
|
ynh_use_go
|
2022-07-21 08:24:29 +02:00
|
|
|
|
2024-03-20 13:39:38 +01:00
|
|
|
ynh_script_progression --message="Building LXC driver..."
|
2024-02-14 14:13:22 +01:00
|
|
|
ynh_setup_source --dest_dir="$install_dir/driver_lxc" --source_id="driver_lxc"
|
|
|
|
pushd "$install_dir/driver_lxc"
|
|
|
|
export GOPATH="$install_dir/driver_lxc/go"
|
|
|
|
export GOCACHE="$install_dir/driver_lxc/.cache"
|
|
|
|
ynh_exec_warn_less "$ynh_go" build
|
|
|
|
popd
|
|
|
|
mv -f "$install_dir/driver_lxc/nomad-driver-lxc" "$data_dir/plugins/nomad-driver-lxc"
|
|
|
|
ynh_secure_remove --file="$install_dir/driver_lxc"
|
2022-07-21 08:24:29 +02:00
|
|
|
fi
|
|
|
|
|
2022-07-20 12:04:29 +02:00
|
|
|
#=================================================
|
|
|
|
# UPDATE A CONFIG FILE
|
|
|
|
#=================================================
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2024-02-14 14:13:22 +01:00
|
|
|
mkdir -p "$config_path"
|
2022-07-21 08:24:29 +02:00
|
|
|
|
2024-02-14 14:13:22 +01:00
|
|
|
ynh_add_config --template="nomad.hcl" --destination="$config_path/nomad.hcl"
|
2022-07-21 08:24:29 +02:00
|
|
|
|
2024-02-14 14:13:22 +01:00
|
|
|
if [ "$node_type" == "server" ]; then
|
|
|
|
ynh_add_config --template="server.hcl" --destination="$config_path/server.hcl"
|
2022-07-21 08:24:29 +02:00
|
|
|
fi
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2024-02-14 14:13:22 +01:00
|
|
|
if [ "$node_type" == "client" ]; then
|
|
|
|
ynh_add_config --template="client.hcl" --destination="$config_path/client.hcl"
|
|
|
|
|
|
|
|
if [ "$driver_lxc" -eq 1 ]; then
|
|
|
|
ynh_add_config --template="driver-lxc.hcl" --destination="$config_path/driver-lxc.hcl"
|
|
|
|
fi
|
2022-07-21 08:24:29 +02:00
|
|
|
fi
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2024-02-14 14:13:22 +01:00
|
|
|
chmod -R go-rwx,u-w "$config_path"
|
|
|
|
chown -R "$app:$app" "$config_path"
|
|
|
|
|
2022-07-20 12:04:29 +02:00
|
|
|
#=================================================
|
2024-02-14 14:13:22 +01:00
|
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
2022-07-20 12:04:29 +02:00
|
|
|
#=================================================
|
2024-02-14 14:13:22 +01:00
|
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Create a dedicated systemd config
|
2024-02-14 14:13:22 +01:00
|
|
|
case "$node_type" in
|
|
|
|
client) systemd_user="root" ;;
|
|
|
|
server) systemd_user="$app" ;;
|
|
|
|
esac
|
2022-07-20 12:04:29 +02:00
|
|
|
ynh_add_systemd_config
|
2024-03-20 11:30:09 +01:00
|
|
|
yunohost service add "$app" --log="/var/log/$app/$app.log" --needs_exposed_ports "$port_rpc" "$port_serf"
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2024-03-20 11:32:08 +01:00
|
|
|
ynh_script_progression --message="Starting $app's systemd service..." --weight=1
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2024-02-14 14:13:22 +01:00
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" --line_match="Nomad agent started"
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-09-03 18:58:58 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|