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

95 lines
3.4 KiB
Bash

#!/bin/bash
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
source /usr/share/yunohost/helpers
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping $app's 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="Installing Go..."
ynh_exec_warn_less ynh_install_go --go_version="$go_version"
ynh_use_go
ynh_script_progression --message="Building LXC driver..."
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"
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 $app's 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