1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/snserver_ynh.git synced 2024-09-03 20:26:22 +02:00
snserver_ynh/scripts/upgrade

462 lines
20 KiB
Text
Raw Normal View History

2020-01-18 10:28:47 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source _common.sh
2021-08-29 00:17:52 +02:00
source ynh_add_swap
2020-01-18 10:28:47 +01:00
source /usr/share/yunohost/helpers
#=================================================
# LOAD SETTINGS
#=================================================
2024-01-15 22:17:38 +01:00
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
2020-01-18 10:28:47 +01:00
2024-01-15 22:17:38 +01:00
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
2020-01-18 10:28:47 +01:00
2024-01-15 22:17:38 +01:00
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? data_dir=$(ynh_app_setting_get --app=$app --key=data_dir)
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#REMOVEME? db_user=$db_name
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
2021-07-08 11:50:04 +02:00
2024-01-15 22:17:38 +01:00
#REMOVEME? port_api_gateway=$(ynh_app_setting_get --app=$app --key=port_api_gateway)
#REMOVEME? port_auth=$(ynh_app_setting_get --app=$app --key=port_auth)
#REMOVEME? port_auth_worker=$(ynh_app_setting_get --app=$app --key=port_auth_worker)
#REMOVEME? port_files=$(ynh_app_setting_get --app=$app --key=port_files)
#REMOVEME? port_syncing_server=$(ynh_app_setting_get --app=$app --key=port_syncing_server)
#REMOVEME? port_syncing_server_worker=$(ynh_app_setting_get --app=$app --key=port_syncing_server_worker)
#REMOVEME? port_workspace=$(ynh_app_setting_get --app=$app --key=port_workspace)
2021-07-08 11:50:04 +02:00
2024-01-15 22:17:38 +01:00
#REMOVEME? redis_db=$(ynh_app_setting_get --app=$app --key=redis_db)
2021-03-06 21:39:49 +01:00
2024-01-15 22:17:38 +01:00
#REMOVEME? jwt_secret=$(ynh_app_setting_get --app=$app --key=jwt_secret)
#REMOVEME? legacy_jwt_secret=$(ynh_app_setting_get --app=$app --key=legacy_jwt_secret)
#REMOVEME? auth_jwt_secret=$(ynh_app_setting_get --app=$app --key=auth_jwt_secret)
#REMOVEME? pseudo_key_params_key=$(ynh_app_setting_get --app=$app --key=pseudo_key_params_key)
#REMOVEME? encryption_server_key=$(ynh_app_setting_get --app=$app --key=encryption_server_key)
#REMOVEME? valet_token_secret=$(ynh_app_setting_get --app=$app --key=valet_token_secret)
2021-07-08 11:50:04 +02:00
2024-01-15 22:17:38 +01:00
#REMOVEME? disable_user_registration=$(ynh_app_setting_get --app=$app --key=DISABLE_USER_REGISTRATION)
#REMOVEME? files_size=$(ynh_app_setting_get --app=$app --key=FILES_SIZE)
2024-01-15 22:17:38 +01:00
config_api_gateway="$install_dir/live/api-gateway.env"
config_auth="$install_dir/live/auth.env"
config_auth_worker="$install_dir/live/auth-worker.env"
config_files="$install_dir/live/files.env"
config_syncing_server="$install_dir/live/syncing-server.env"
config_syncing_server_worker="$install_dir/live/syncing-server-worker.env"
config_workspace="$install_dir/live/workspace.env"
2021-07-08 11:50:04 +02:00
2024-01-15 22:17:38 +01:00
#REMOVEME? nodejs_version_installed=$(ynh_app_setting_get --app=$app --key=nodejs_version)
2020-01-18 10:28:47 +01:00
#=================================================
# CHECK VERSION
#=================================================
2022-08-31 02:25:01 +02:00
ynh_script_progression --message="Checking version..."
2020-01-18 10:28:47 +01:00
upgrade_type=$(ynh_check_app_version_changed)
2021-02-06 21:41:33 +01:00
#=================================================
# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP
#=================================================
2024-01-15 22:17:38 +01:00
#REMOVEME? ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1
2021-02-06 21:41:33 +01:00
# Backup the current version of the app
2024-01-15 22:17:38 +01:00
#REMOVEME? ynh_backup_before_upgrade
#REMOVEME? ynh_clean_setup () {
2022-08-31 02:25:01 +02:00
# Restore it if the upgrade fails
2024-01-15 22:17:38 +01:00
#REMOVEME? ynh_restore_upgradebackup
2021-02-06 21:41:33 +01:00
}
# Exit if an error occurs during the execution of the script
2024-01-15 22:17:38 +01:00
#REMOVEME? ynh_abort_if_errors
2021-02-06 21:41:33 +01:00
2021-07-08 11:50:04 +02:00
#=================================================
# STANDARD UPGRADE STEPS
#=================================================
# STOP SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Stopping a systemd service..." --weight=1
2022-08-04 17:28:39 +02:00
ynh_systemd_action \
2022-08-31 02:25:01 +02:00
--service_name="$app-api-gateway" \
--action="stop" \
--log_path="/var/log/$app/api-gateway.log"
2022-08-04 17:28:39 +02:00
ynh_systemd_action \
2022-08-31 02:25:01 +02:00
--service_name="$app-auth" \
--action="stop" \
--log_path="/var/log/$app/auth.log"
2022-08-04 17:28:39 +02:00
ynh_systemd_action \
2022-08-31 02:25:01 +02:00
--service_name="$app-auth-worker" \
--action="stop" \
--log_path="/var/log/$app/auth-worker.log"
2022-08-04 17:28:39 +02:00
ynh_systemd_action \
2022-08-31 02:25:01 +02:00
--service_name="$app-files" \
--action="stop" \
--log_path="/var/log/$app/files.log"
2022-08-04 17:28:39 +02:00
ynh_systemd_action \
2022-08-31 02:25:01 +02:00
--service_name="$app-syncing-server" \
--action="stop" \
--log_path="/var/log/$app/syncing-server.log"
2022-08-04 17:28:39 +02:00
ynh_systemd_action \
2022-08-31 02:25:01 +02:00
--service_name="$app-syncing-server-worker" \
--action="stop" \
--log_path="/var/log/$app/syncing-server-worker.log"
2022-10-25 18:42:07 +02:00
ynh_systemd_action \
--service_name="$app-workspace" \
--action="stop" \
--log_path="/var/log/$app/workspace.log"
2021-07-08 11:50:04 +02:00
2020-01-18 10:28:47 +01:00
#=================================================
# ENSURE DOWNWARD COMPATIBILITY
#=================================================
2020-12-24 12:11:42 +01:00
ynh_script_progression --message="Ensuring downward compatibility..." --weight=1
2020-01-18 10:28:47 +01:00
2024-01-15 22:17:38 +01:00
# If install_dir doesn't exist, create it
if [ -z "$install_dir" ]; then
#REMOVEME? install_dir=/opt/yunohost/$app
#REMOVEME? ynh_app_setting_set --app=$app --key=install_dir --value=$install_dir
2020-01-18 10:28:47 +01:00
fi
2021-03-06 21:39:49 +01:00
# If redis_db doesn't exist, create it
if [ -z "$redis_db" ]; then
2022-08-31 02:25:01 +02:00
redis_db=$(ynh_redis_get_free_db)
ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db"
2021-03-06 21:39:49 +01:00
fi
2022-08-10 23:15:43 +02:00
# If one port_* doesn't exist, create all new
if [[ -z "$port_api_gateway" || \
2022-08-31 02:25:01 +02:00
-z "$port_auth" || \
-z "$port_auth_worker" || \
-z "$port_files" || \
-z "$port_syncing_server" || \
2022-10-25 18:42:07 +02:00
-z "$port_syncing_server_worker" || \
-z "$port_workspace" ]]; then
2024-01-15 22:17:38 +01:00
#REMOVEME? port_api_gateway=$(ynh_find_port --port=3000)
#REMOVEME? port_auth=$(ynh_find_port --port=$((port_api_gateway+1)))
#REMOVEME? port_auth_worker=$(ynh_find_port --port=$((port_auth+1)))
#REMOVEME? port_files=$(ynh_find_port --port=$((port_auth_worker+1)))
#REMOVEME? port_syncing_server=$(ynh_find_port --port=$((port_files+1)))
#REMOVEME? port_syncing_server_worker=$(ynh_find_port --port=$((port_syncing_server+1)))
#REMOVEME? port_workspace=$(ynh_find_port --port=$((port_syncing_server_worker+1)))
#REMOVEME? ynh_app_setting_set --app=$app --key=port_api_gateway --value=$port_api_gateway
#REMOVEME? ynh_app_setting_set --app=$app --key=port_auth --value=$port_auth
#REMOVEME? ynh_app_setting_set --app=$app --key=port_auth_worker --value=$port_auth_worker
#REMOVEME? ynh_app_setting_set --app=$app --key=port_files --value=$port_files
#REMOVEME? ynh_app_setting_set --app=$app --key=port_syncing_server --value=$port_syncing_server
#REMOVEME? ynh_app_setting_set --app=$app --key=port_syncing_server_worker --value=$port_syncing_server_worker
#REMOVEME? ynh_app_setting_set --app=$app --key=port_workspace --value=$port_workspace
2022-08-04 17:28:39 +02:00
fi
2021-07-08 11:50:04 +02:00
# If jwt_secret doesn't exist, create it
if [ -z "$jwt_secret" ]; then
2022-08-31 02:25:01 +02:00
jwt_secret=$(ynh_string_random --length=48 | base64)
ynh_app_setting_set --app=$app --key=jwt_secret --value=$jwt_secret
2021-07-08 11:50:04 +02:00
fi
# If legacy_jwt_secret doesn't exist, create it
if [ -z "$legacy_jwt_secret" ]; then
2022-08-31 02:25:01 +02:00
legacy_jwt_secret=$(ynh_string_random --length=48 | base64)
ynh_app_setting_set --app=$app --key=legacy_jwt_secret --value=$legacy_jwt_secret
2021-07-08 11:50:04 +02:00
fi
# If auth_jwt_secret doesn't exist, create it
if [ -z "$auth_jwt_secret" ]; then
2022-08-31 02:25:01 +02:00
auth_jwt_secret=$(ynh_string_random --length=48 | base64)
ynh_app_setting_set --app=$app --key=auth_jwt_secret --value=$auth_jwt_secret
2021-07-08 11:50:04 +02:00
fi
# If pseudo_key_params_key doesn't exist, create it
if [ -z "$pseudo_key_params_key" ]; then
2022-08-31 02:25:01 +02:00
pseudo_key_params_key=$(ynh_string_random --length=48 | base64)
ynh_app_setting_set --app=$app --key=pseudo_key_params_key --value=$pseudo_key_params_key
2021-07-08 11:50:04 +02:00
fi
# If encryption_server_key doesn't exist, create it
if [ -z "$encryption_server_key" ]; then
2022-08-31 02:25:01 +02:00
encryption_server_key=$(hexdump -n 32 -e '4/4 "%08X"' /dev/random) # 32bytes hex key is required
ynh_app_setting_set --app=$app --key=encryption_server_key --value=$encryption_server_key
2021-07-08 11:50:04 +02:00
fi
2022-08-04 17:28:39 +02:00
# If valet_token_secret doesn't exist, create it
if [ -z "$valet_token_secret" ]; then
2022-08-31 02:25:01 +02:00
valet_token_secret=$(ynh_string_random --length=48 | base64)
ynh_app_setting_set --app=$app --key=valet_token_secret --value=$valet_token_secret
fi
# If disable_user_registration doesn't exist, create it
2022-08-09 21:17:53 +02:00
if [ -z "$disable_user_registration" ]; then
2022-08-31 02:25:01 +02:00
disable_user_registration=false
ynh_app_setting_set --app=$app --key=DISABLE_USER_REGISTRATION --value=$disable_user_registration
fi
# If files_zise doesn't exist, create it
if [ -z "$files_size" ]; then
2022-08-31 02:25:01 +02:00
files_size=100
ynh_app_setting_set --app=$app --key=FILES_SIZE --value=$files_size
fi
2022-08-04 17:28:39 +02:00
# Remove old Settings, Services, Files, Dependencies
2024-01-15 22:17:38 +01:00
# If install_dir_www exist, delete it
#REMOVEME? api_gateway_version_installed=$(ynh_app_setting_get --app=$app --key=api_gateway_version)
#REMOVEME? auth_version_installed=$(ynh_app_setting_get --app=$app --key=auth_version)
#REMOVEME? syncing_server_version_installed=$(ynh_app_setting_get --app=$app --key=syncing_server_version)
#REMOVEME? install_dir_www=$(ynh_app_setting_get --app=$app --key=install_dir_www)
#REMOVEME? install_dir_extensions=$(ynh_app_setting_get --app=$app --key=install_dir_extensions)
2022-08-09 21:17:53 +02:00
if [ -n ${api_gateway_version_installed+x} ]; then
2022-08-31 02:25:01 +02:00
ynh_app_setting_delete --app=$app --key=api_gateway_version_installed
2022-08-09 21:17:53 +02:00
fi
if [ -n ${auth_version_installed+x} ]; then
2022-08-31 02:25:01 +02:00
ynh_app_setting_delete --app=$app --key=auth_version_installe
2022-08-09 21:17:53 +02:00
fi
if [ -n ${syncing_server_version_installed+x} ]; then
2022-08-31 02:25:01 +02:00
ynh_app_setting_delete --app=$app --key=syncing_server_version_installed
2022-08-09 21:17:53 +02:00
fi
2024-01-15 22:17:38 +01:00
if [ -n ${install_dir_www+x} ]; then
ynh_app_setting_delete --app=$app --key=install_dir_www
2022-08-01 21:46:14 +02:00
fi
2024-01-15 22:17:38 +01:00
# If install_dir_extensions exist, delete it
if [ -n ${install_dir_extensions+x} ]; then
ynh_app_setting_delete --app=$app --key=install_dir_extensions
2022-08-01 21:46:14 +02:00
fi
# If permission help exists, delete it
2024-01-15 22:17:38 +01:00
#REMOVEME? if ynh_permission_exists --permission="help"
2022-08-01 21:46:14 +02:00
then
2022-08-31 02:25:01 +02:00
ynh_permission_delete --permission="help"
2022-08-01 21:46:14 +02:00
fi
# If old service exsits; remove it
2022-08-04 17:28:39 +02:00
if ynh_exec_warn_less yunohost service status "$app-syncing-server-js" >/dev/null
then
2022-08-31 02:25:01 +02:00
ynh_script_progression --message="Removing old service..." --weight=1
yunohost service remove "$app-syncing-server-js"
ynh_remove_systemd_config --service="$app-syncing-server-js"
ynh_reset_systemd
2021-07-11 17:36:53 +02:00
fi
2022-08-04 17:28:39 +02:00
if ynh_exec_warn_less yunohost service status "$app-syncing-server-js-worker" >/dev/null
2021-07-08 11:50:04 +02:00
then
2022-08-31 02:25:01 +02:00
ynh_script_progression --message="Removing old service..." --weight=1
yunohost service remove "$app-syncing-server-js-worker"
ynh_remove_systemd_config --service="$app-syncing-server-js-worker"
ynh_reset_systemd
2021-07-08 11:50:04 +02:00
fi
2021-10-30 09:59:53 +02:00
# Remove unneeded data
2022-08-01 21:46:14 +02:00
if [ -e "/var/www/$app" ]; then
2022-08-31 02:25:01 +02:00
ynh_secure_remove --file="/var/www/$app"
2022-08-01 21:46:14 +02:00
fi
2021-10-30 09:59:53 +02:00
2024-01-15 22:17:38 +01:00
# If data_dir doesn't exist, create it
2022-08-04 17:28:39 +02:00
# CREATE DATA DIRECTORY
2024-01-15 22:17:38 +01:00
if [ -z "$data_dir" ]; then
data_dir=/home/yunohost.app/$app
#REMOVEME? ynh_app_setting_set --app=$app --key=data_dir --value=$data_dir
2022-08-04 17:28:39 +02:00
2024-01-15 22:17:38 +01:00
mkdir -p $data_dir/uploads
2022-08-04 17:28:39 +02:00
2024-01-15 22:17:38 +01:00
chmod -R 750 "$data_dir"
chmod -R o-rwx "$data_dir"
chown -R $app:$app "$data_dir"
2022-08-04 17:28:39 +02:00
fi
2020-01-18 10:28:47 +01:00
#=================================================
2021-07-08 11:50:04 +02:00
# CREATE DEDICATED USER
2020-01-18 10:28:47 +01:00
#=================================================
2024-01-15 22:17:38 +01:00
#REMOVEME? ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1
2020-01-18 10:28:47 +01:00
2021-07-08 11:50:04 +02:00
# Create a dedicated user (if not existing)
2024-01-15 22:17:38 +01:00
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
2020-01-18 10:28:47 +01:00
#=================================================
# DOWNLOAD, CHECK AND UNPACK SOURCE
#=================================================
2022-08-31 02:25:01 +02:00
2022-08-04 17:28:39 +02:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
2020-01-18 10:28:47 +01:00
then
2022-08-31 02:25:01 +02:00
ynh_script_progression --message="Upgrading source files..." --weight=1
2021-07-08 11:50:04 +02:00
2022-08-31 02:25:01 +02:00
# Download, check integrity, uncompress and patch the source from app.src
2024-01-15 22:17:38 +01:00
#REMOVEME? ynh_secure_remove --file="$install_dir/live"
mkdir -p "$install_dir/live"
ynh_setup_source --dest_dir="$install_dir/live"
cp "$YNH_APP_BASEDIR/sources/extra_files/cron.sh" "$install_dir/cron.sh"
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:$app "$install_dir"
2021-02-07 00:02:09 +01:00
fi
2020-01-18 10:28:47 +01:00
#=================================================
# UPGRADE DEPENDENCIES
#=================================================
2024-01-15 22:17:38 +01:00
#REMOVEME? ynh_script_progression --message="Upgrading dependencies..." --weight=1
2020-01-18 10:28:47 +01:00
2024-01-15 22:17:38 +01:00
#REMOVEME? ynh_install_app_dependencies $pkg_dependencies
2022-08-31 02:25:01 +02:00
ynh_install_nodejs --nodejs_version=$nodejs_version
2024-01-15 22:17:38 +01:00
#REMOVEME? ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ stable main" --package="yarn" --key="https://dl.yarnpkg.com/debian/pubkey.gpg"
2020-01-18 10:28:47 +01:00
#=================================================
2022-08-31 02:25:01 +02:00
# NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Upgrading NGINX web server configuration..." --weight=1
# Create a dedicated NGINX config
ynh_add_nginx_config
2020-01-18 10:28:47 +01:00
#=================================================
2022-08-31 02:25:01 +02:00
# SPECIFIC UPGRADE
2020-01-18 10:28:47 +01:00
#=================================================
2021-08-29 00:17:52 +02:00
# ADD SWAP
#=================================================
ynh_script_progression --message="Adding swap..."
2022-08-31 04:24:01 +02:00
if [ ${PACKAGE_CHECK_EXEC:-0} -eq 0 ]; then
ynh_add_swap --size=$swap_needed
fi
2021-08-29 00:17:52 +02:00
#=================================================
2022-08-31 02:25:01 +02:00
# UPDATE A CONFIG FILE
2020-01-18 10:28:47 +01:00
#=================================================
2022-08-31 02:25:01 +02:00
ynh_script_progression --message="Updating a configuration file..." --weight=2
2021-02-06 01:44:31 +01:00
2022-08-04 17:28:39 +02:00
ynh_add_config --template="env_api-gateway.env.sample" --destination="$config_api_gateway"
2021-07-08 11:50:04 +02:00
ynh_add_config --template="env_auth.env.sample" --destination="$config_auth"
ynh_add_config --template="env_auth-worker.env.sample" --destination="$config_auth_worker"
2022-08-04 17:28:39 +02:00
ynh_add_config --template="env_files.env.sample" --destination="$config_files"
ynh_add_config --template="env_syncing-server.env.sample" --destination="$config_syncing_server"
ynh_add_config --template="env_syncing-server-worker.env.sample" --destination="$config_syncing_server_worker"
2022-10-25 18:42:07 +02:00
ynh_add_config --template="env_workspace.env.sample" --destination="$config_workspace"
2021-01-24 11:36:36 +01:00
2020-01-18 10:28:47 +01:00
#=================================================
2021-05-01 21:48:58 +02:00
# INSTALLING Standard Notes - Syncing Server
2020-01-18 10:28:47 +01:00
#=================================================
2020-12-20 14:22:36 +01:00
if [ "$upgrade_type" == "UPGRADE_APP" ]
then
2022-08-31 02:25:01 +02:00
ynh_script_progression --message="Installing Standard Notes - Syncing Server..." --weight=93
ynh_use_nodejs
2024-01-15 22:17:38 +01:00
pushd "$install_dir/live"
2022-10-25 18:42:07 +02:00
ynh_exec_warn_less ynh_exec_as $app env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" $ynh_node_load_PATH yarn install --immutable
ynh_exec_warn_less ynh_exec_as $app env NODE_ENV="production" NODE_OPTIONS="--max-old-space-size=$node_max_old_space_size" $ynh_node_load_PATH yarn build
2022-08-31 02:25:01 +02:00
popd
2020-12-20 14:22:36 +01:00
fi
2020-01-18 10:28:47 +01:00
#=================================================
# SETUP SYSTEMD
#=================================================
2020-12-24 12:11:42 +01:00
ynh_script_progression --message="Upgrading systemd configuration..." --weight=1
2020-01-18 10:28:47 +01:00
# Create a dedicated systemd config
2022-08-04 17:28:39 +02:00
ynh_add_systemd_config --service="$app-api-gateway" --template="systemd_api-gateway.service"
2021-07-08 11:50:04 +02:00
ynh_add_systemd_config --service="$app-auth" --template="systemd_auth.service"
ynh_add_systemd_config --service="$app-auth-worker" --template="systemd_auth-worker.service"
2022-08-04 17:28:39 +02:00
ynh_add_systemd_config --service="$app-files" --template="systemd_files.service"
ynh_add_systemd_config --service="$app-syncing-server" --template="systemd_syncing-server.service"
ynh_add_systemd_config --service="$app-syncing-server-worker" --template="systemd_syncing-server-worker.service"
2022-10-25 18:42:07 +02:00
ynh_add_systemd_config --service="$app-workspace" --template="systemd_workspace.service"
2020-01-18 10:28:47 +01:00
2020-12-20 14:22:36 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
2021-07-08 11:50:04 +02:00
# SETUP LOGROTATE
2020-01-18 10:28:47 +01:00
#=================================================
2021-07-08 11:50:04 +02:00
ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1
2020-12-20 14:22:36 +01:00
2020-12-27 23:18:55 +01:00
mkdir -p "/var/log/$app"
2021-07-08 11:50:04 +02:00
chown -R "$app": "/var/log/$app"
# Use logrotate to manage application logfile(s)
2022-08-04 17:28:39 +02:00
ynh_use_logrotate --logfile="/var/log/$app/api-gateway.log"
2021-07-08 11:50:04 +02:00
ynh_use_logrotate --logfile="/var/log/$app/auth.log"
ynh_use_logrotate --logfile="/var/log/$app/auth-worker.log"
2022-08-04 17:28:39 +02:00
ynh_use_logrotate --logfile="/var/log/$app/files.log"
ynh_use_logrotate --logfile="/var/log/$app/syncing-server.log"
ynh_use_logrotate --logfile="/var/log/$app/syncing-server-worker.log"
2022-10-25 18:42:07 +02:00
ynh_use_logrotate --logfile="/var/log/$app/workspace.log"
2020-12-20 14:22:36 +01:00
#=================================================
2021-07-08 11:50:04 +02:00
# INTEGRATE SERVICE IN YUNOHOST
2020-12-20 14:22:36 +01:00
#=================================================
2022-08-31 02:25:01 +02:00
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
2020-12-20 14:22:36 +01:00
2022-08-04 17:28:39 +02:00
yunohost service add "$app-api-gateway" --description="Standard Notes - API Gateway" --log="/var/log/$app/api-gateway.log"
2021-07-08 11:50:04 +02:00
yunohost service add "$app-auth" --description="Standard Notes - Auth" --log="/var/log/$app/auth.log"
yunohost service add "$app-auth-worker" --description="Standard Notes - Auth - Worker" --log="/var/log/$app/auth-worker.log"
2022-08-04 17:28:39 +02:00
yunohost service add "$app-files" --description="Standard Notes - Files" --log="/var/log/$app/files.log"
yunohost service add "$app-syncing-server" --description="Standard Notes - Syncing Server" --log="/var/log/$app/syncing-server.log"
yunohost service add "$app-syncing-server-worker" --description="Standard Notes - Syncing Server - Worker" --log="/var/log/$app/syncing-server-worker.log"
2022-10-25 18:42:07 +02:00
yunohost service add "$app-workspace" --description="Standard Notes - Workspace" --log="/var/log/$app/workspace.log"
2020-12-20 14:22:36 +01:00
2020-12-24 12:11:42 +01:00
#=================================================
2021-07-08 11:50:04 +02:00
# START SYSTEMD SERVICE
2020-12-24 12:11:42 +01:00
#=================================================
2021-07-08 11:50:04 +02:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2020-12-24 12:11:42 +01:00
2021-07-08 11:50:04 +02:00
# Start a systemd service
ynh_systemd_action \
2022-08-31 02:25:01 +02:00
--service_name="$app-api-gateway" \
--action="start" \
--log_path="/var/log/$app/api-gateway.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
2021-07-08 11:50:04 +02:00
ynh_systemd_action \
2022-08-31 02:25:01 +02:00
--service_name="$app-auth" \
--action="start" \
--log_path="/var/log/$app/auth.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
2021-07-08 11:50:04 +02:00
ynh_systemd_action \
2022-08-31 02:25:01 +02:00
--service_name="$app-auth-worker" \
--action="start" \
--log_path="/var/log/$app/auth-worker.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
2021-07-08 11:50:04 +02:00
ynh_systemd_action \
2022-08-31 02:25:01 +02:00
--service_name="$app-files" \
--action="start" \
--log_path="/var/log/$app/files.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
2022-08-04 17:28:39 +02:00
ynh_systemd_action \
2022-08-31 02:25:01 +02:00
--service_name="$app-syncing-server" \
--action="start" \
--log_path="/var/log/$app/syncing-server.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
2022-08-04 17:28:39 +02:00
ynh_systemd_action \
2022-08-31 02:25:01 +02:00
--service_name="$app-syncing-server-worker" \
--action="start" \
--log_path="/var/log/$app/syncing-server-worker.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
2022-10-25 18:42:07 +02:00
ynh_systemd_action \
--service_name="$app-workspace" \
--action="start" \
--log_path="/var/log/$app/workspace.log" \
--line_match='^.*Server started on port.*$|^.*Starting worker.*$'
2020-12-24 12:11:42 +01:00
2022-08-08 01:37:39 +02:00
#=================================================
# SETUP A CRON
#=================================================
ynh_script_progression --message="Setup a cron..."
2024-01-15 22:17:38 +01:00
ynh_add_config --template="../conf/cron.env" --destination="$install_dir/cron.env"
2022-08-08 01:37:39 +02:00
ynh_add_config --template="../conf/cron" --destination="/etc/cron.d/$app"
chown root: "/etc/cron.d/$app"
chmod 640 "/etc/cron.d/$app"
2020-12-20 14:22:36 +01:00
#=================================================
2022-08-31 02:25:01 +02:00
# UPGRADE FAIL2BAN
2020-12-20 14:22:36 +01:00
#=================================================
2022-08-31 02:25:01 +02:00
ynh_script_progression --message="Reconfiguring Fail2Ban..." --weight=1
2020-12-20 14:22:36 +01:00
2022-08-31 02:25:01 +02:00
# Create a dedicated Fail2Ban config
2021-05-09 14:50:38 +02:00
ynh_add_fail2ban_config --use_template
2020-01-18 10:28:47 +01:00
#=================================================
# RELOAD NGINX
#=================================================
2024-01-15 22:17:38 +01:00
#REMOVEME? ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2020-01-18 10:28:47 +01:00
2024-01-15 22:17:38 +01:00
#REMOVEME? ynh_systemd_action --service_name=nginx --action=reload
2020-01-18 10:28:47 +01:00
#=================================================
# END OF SCRIPT
#=================================================
2020-12-24 12:11:42 +01:00
ynh_script_progression --message="Upgrade of $app completed" --last