2022-07-20 12:04:29 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source _common.sh
|
2022-07-21 08:24:29 +02:00
|
|
|
source ynh_install_go
|
2022-07-20 12:04:29 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
2022-07-21 08:24:29 +02:00
|
|
|
config_path=$(ynh_app_setting_get --app=$app --key=config_path)
|
2022-07-21 19:56:55 +02:00
|
|
|
datadir=$(ynh_app_setting_get --app=$app --key=datadir)
|
2022-07-21 08:24:29 +02:00
|
|
|
node_type=$(ynh_app_setting_get --app=$app --key=node_type)
|
|
|
|
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)
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK VERSION
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Checking version..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
upgrade_type=$(ynh_check_app_version_changed)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Backing up the app before upgrading (may take a while)..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Backup the current version of the app
|
|
|
|
ynh_backup_before_upgrade
|
|
|
|
ynh_clean_setup () {
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_clean_check_starting
|
2022-07-20 12:04:29 +02:00
|
|
|
# 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
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Stopping a systemd service..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# ENSURE DOWNWARD COMPATIBILITY
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Ensuring downward compatibility..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# 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
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Making sure dedicated system user exists..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Create a dedicated user (if not existing)
|
2022-07-21 08:24:29 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# UPGRADE DEPENDENCIES
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Upgrading dependencies..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 08:24:29 +02:00
|
|
|
if [ "$node_type" == "client" ]
|
|
|
|
then
|
|
|
|
ynh_install_app_dependencies $client_pkg_dependencies
|
|
|
|
ynh_install_go --go_version=$go_version
|
|
|
|
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"
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Upgrading NGINX web server configuration..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Create a dedicated NGINX config
|
|
|
|
ynh_add_nginx_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC UPGRADE
|
|
|
|
#=================================================
|
2022-07-21 08:24:29 +02:00
|
|
|
# BUILD LXC DRIVER
|
2022-07-20 12:04:29 +02:00
|
|
|
#=================================================
|
|
|
|
|
2022-07-21 08:24:29 +02:00
|
|
|
if [ "$node_type" == "client" ]
|
|
|
|
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_go build
|
|
|
|
popd
|
|
|
|
|
|
|
|
mv -f $tempdir/nomad-driver-lxc $datadir/plugins/nomad-driver-lxc
|
|
|
|
|
|
|
|
ynh_secure_remove --file="$tempdir"
|
|
|
|
fi
|
|
|
|
|
2022-07-20 12:04:29 +02:00
|
|
|
#=================================================
|
|
|
|
# UPDATE A CONFIG FILE
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Updating a configuration file..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 08:24:29 +02:00
|
|
|
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
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 08:24:29 +02:00
|
|
|
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"
|
|
|
|
fi
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SETUP SYSTEMD
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Upgrading systemd configuration..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 08:24:29 +02:00
|
|
|
systemd_user=$app
|
|
|
|
if [ "$node_type" == "client" ]
|
|
|
|
then
|
|
|
|
systemd_user="root"
|
|
|
|
fi
|
2022-07-20 12:04:29 +02:00
|
|
|
# Create a dedicated systemd config
|
|
|
|
ynh_add_systemd_config
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SETUP LOGROTATE
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Upgrading logrotate configuration..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
# Use logrotate to manage app-specific logfile(s)
|
|
|
|
ynh_use_logrotate --non-append
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# INTEGRATE SERVICE IN YUNOHOST
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 19:51:27 +02:00
|
|
|
needs_exposed_ports="$rpc_port"
|
|
|
|
if [ "$node_type" == "server" ]
|
|
|
|
then
|
|
|
|
needs_exposed_ports="$serf_port $needs_exposed_ports"
|
|
|
|
fi
|
2022-07-21 23:14:02 +02:00
|
|
|
yunohost service add $app --log="/var/log/$app/$app.log" --needs_exposed_ports $needs_exposed_ports
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
2022-07-21 08:24:29 +02: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
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
2022-07-20 12:04:29 +02:00
|
|
|
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-07-20 12:07:54 +02:00
|
|
|
ynh_script_progression --message="Upgrade of $app completed"
|