mirror of
https://github.com/YunoHost-Apps/nomad_ynh.git
synced 2024-09-03 19:55:53 +02:00
230 lines
7.4 KiB
Bash
230 lines
7.4 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# GENERIC START
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
source _common.sh
|
|
source ynh_install_go
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# LOAD SETTINGS
|
|
#=================================================
|
|
ynh_script_progression --message="Loading installation settings..."
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
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)
|
|
|
|
#=================================================
|
|
# CHECK VERSION
|
|
#=================================================
|
|
ynh_script_progression --message="Checking version..."
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
#=================================================
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
#=================================================
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
|
|
|
# Backup the current version of the app
|
|
ynh_backup_before_upgrade
|
|
ynh_clean_setup () {
|
|
ynh_clean_check_starting
|
|
# Restore it if the upgrade fails
|
|
ynh_restore_upgradebackup
|
|
}
|
|
# Exit if an error occurs during the execution of the script
|
|
ynh_abort_if_errors
|
|
|
|
#=================================================
|
|
# STANDARD UPGRADE STEPS
|
|
#=================================================
|
|
# STOP SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
|
|
|
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..."
|
|
|
|
# Cleaning legacy permissions
|
|
if ynh_legacy_permissions_exists; then
|
|
ynh_legacy_permissions_delete_all
|
|
|
|
ynh_app_setting_delete --app=$app --key=is_public
|
|
fi
|
|
|
|
#=================================================
|
|
# CREATE DEDICATED USER
|
|
#=================================================
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
|
|
|
# Create a dedicated user (if not existing)
|
|
ynh_system_user_create --username=$app
|
|
|
|
#=================================================
|
|
# UPGRADE DEPENDENCIES
|
|
#=================================================
|
|
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_exec_warn_less ynh_install_go --go_version=$go_version
|
|
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"
|
|
|
|
#=================================================
|
|
# NGINX CONFIGURATION
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
|
|
|
# Create a dedicated NGINX config
|
|
ynh_add_nginx_config
|
|
|
|
#=================================================
|
|
# SPECIFIC UPGRADE
|
|
#=================================================
|
|
# BUILD DRIVERS
|
|
#=================================================
|
|
|
|
if [ "$node_type" == "client" ]
|
|
then
|
|
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"
|
|
|
|
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
|
|
|
|
ynh_secure_remove --file="$tempdir"
|
|
fi
|
|
fi
|
|
|
|
#=================================================
|
|
# UPDATE A CONFIG FILE
|
|
#=================================================
|
|
ynh_script_progression --message="Updating a configuration file..."
|
|
|
|
mkdir -p $config_path
|
|
chmod 750 "$config_path"
|
|
chmod -R o-rwx "$config_path"
|
|
chown -R $app:$app "$config_path"
|
|
|
|
ynh_add_config --template="../conf/nomad.hcl" --destination="$config_path/nomad.hcl"
|
|
chmod 400 "$config_path/nomad.hcl"
|
|
chown $app:$app "$config_path/nomad.hcl"
|
|
|
|
if [ "$node_type" == "server" ]
|
|
then
|
|
ynh_add_config --template="../conf/server.hcl" --destination="$config_path/server.hcl"
|
|
chmod 400 "$config_path/server.hcl"
|
|
chown $app:$app "$config_path/server.hcl"
|
|
fi
|
|
|
|
if [ "$node_type" == "client" ]
|
|
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"
|
|
fi
|
|
fi
|
|
|
|
#=================================================
|
|
# SETUP SYSTEMD
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
|
|
|
systemd_user=$app
|
|
if [ "$node_type" == "client" ]
|
|
then
|
|
systemd_user="root"
|
|
fi
|
|
# Create a dedicated systemd config
|
|
ynh_add_systemd_config
|
|
|
|
#=================================================
|
|
# GENERIC FINALIZATION
|
|
#=================================================
|
|
# SETUP LOGROTATE
|
|
#=================================================
|
|
ynh_script_progression --message="Upgrading logrotate configuration..."
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
ynh_use_logrotate --non-append
|
|
|
|
#=================================================
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
#=================================================
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
|
|
|
needs_exposed_ports="$rpc_port"
|
|
if [ "$node_type" == "server" ]
|
|
then
|
|
needs_exposed_ports="$serf_port $needs_exposed_ports"
|
|
fi
|
|
yunohost service add $app --log="/var/log/$app/$app.log" --needs_exposed_ports $needs_exposed_ports
|
|
|
|
#=================================================
|
|
# START SYSTEMD SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Starting a systemd service..."
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" --line_match="Nomad agent started"
|
|
|
|
#=================================================
|
|
# RELOAD NGINX
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|