mirror of
https://github.com/YunoHost-Apps/nomad_ynh.git
synced 2024-09-03 19:55:53 +02:00
100 lines
3.5 KiB
Bash
100 lines
3.5 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source ynh_install_go
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name="$app" --action="stop" --log_path="/var/log/$app/$app.log"
|
|
|
|
#=================================================
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
#=================================================
|
|
# ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
|
|
|
|
#=================================================
|
|
# BUILD DRIVERS
|
|
#=================================================
|
|
if [ "$node_type" == "client" ] && [ "$driver_lxc" -eq 1 ]; then
|
|
ynh_script_progression --message="Building LXC driver..."
|
|
|
|
ynh_exec_warn_less ynh_install_go --go_version="$go_version"
|
|
|
|
ynh_setup_source --dest_dir="$install_dir/driver_lxc" --source_id="driver_lxc"
|
|
pushd "$install_dir/driver_lxc"
|
|
ynh_use_go
|
|
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"
|
|
fi
|
|
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Updating a configuration file..." --weight=1
|
|
|
|
mkdir -p "$config_path"
|
|
|
|
ynh_add_config --template="nomad.hcl" --destination="$config_path/nomad.hcl"
|
|
|
|
if [ "$node_type" == "server" ]; then
|
|
ynh_add_config --template="server.hcl" --destination="$config_path/server.hcl"
|
|
fi
|
|
|
|
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
|
|
fi
|
|
|
|
chmod -R go-rwx,u-w "$config_path"
|
|
chown -R "$app:$app" "$config_path"
|
|
|
|
#=================================================
|
|
# REAPPLY SYSTEM CONFIGURATIONS
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
# Create a dedicated systemd config
|
|
case "$node_type" in
|
|
client) systemd_user="root" ;;
|
|
server) systemd_user="$app" ;;
|
|
esac
|
|
ynh_add_systemd_config
|
|
yunohost service add "$app" --log="/var/log/$app/$app.log" --needs_exposed_ports="$port_rpc $port_serf"
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_use_logrotate --non-append
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name="$app" --action="start" --log_path="/var/log/$app/$app.log" --line_match="Nomad agent started"
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed" --last
|