2016-05-07 18:21:06 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# GENERIC START
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-07-04 21:16:34 +02:00
|
|
|
|
2022-03-06 19:01:21 +01:00
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
2018-07-04 20:53:50 +02:00
|
|
|
source ../settings/scripts/_common.sh
|
2017-05-01 15:47:20 +02:00
|
|
|
source /usr/share/yunohost/helpers
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2018-05-28 00:30:42 +02:00
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
2019-03-03 20:32:26 +01:00
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
|
|
|
}
|
2018-05-28 00:30:42 +02:00
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2019-05-18 20:15:36 +02:00
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
path_url=$(ynh_app_setting_get --app=$app --key=path)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
2017-05-01 15:47:20 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..." --weight=2
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2022-03-06 19:01:21 +01:00
|
|
|
test ! -d $final_path \
|
|
|
|
|| ynh_die --message="There is already a directory: $final_path "
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# STANDARD RESTORATION STEPS
|
2021-03-21 23:13:21 +01:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# RECREATE THE DEDICATED USER
|
2021-03-21 23:13:21 +01:00
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Recreating the dedicated system user..." --weight=3
|
|
|
|
|
|
|
|
# Create the dedicated user (if not existing)
|
2021-06-26 12:08:49 +02:00
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
2021-03-21 23:13:21 +01:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# RESTORE THE APP MAIN DIR
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2020-12-19 23:34:40 +01:00
|
|
|
ynh_script_progression --message="Restoring the app main directory..." --weight=2
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_restore_file --origin_path="$final_path"
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2022-03-06 19:01:21 +01:00
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app: "$final_path"
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# SPECIFIC RESTORATION
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# REINSTALL DEPENDENCIES
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=35
|
2017-05-01 15:47:20 +02:00
|
|
|
|
2022-03-06 19:01:21 +01:00
|
|
|
# Define and install dependencies
|
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2017-05-01 15:47:20 +02:00
|
|
|
|
2022-06-29 01:07:32 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoring the NGINX web server configuration..."
|
|
|
|
|
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# RESTORE VARIOUS FILES
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
ynh_script_progression --message="Restoring various files..."
|
2017-05-01 15:47:20 +02:00
|
|
|
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/uwsgi/apps-available/$app.ini"
|
2022-03-09 20:30:52 +01:00
|
|
|
mkdir -p /var/log/uwsgi/$app
|
2020-04-10 22:02:55 +02:00
|
|
|
chown $app:root /var/log/uwsgi/$app
|
2022-03-09 20:30:52 +01:00
|
|
|
chmod -R u=rwX,g=rX,o= /var/log/uwsgi/$app
|
2020-04-11 14:18:51 +02:00
|
|
|
ynh_check_global_uwsgi_config
|
2021-06-26 12:33:40 +02:00
|
|
|
systemctl enable "uwsgi-app@$app.service" --quiet
|
2016-07-04 21:16:34 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# START SYSTEMD SERVICE
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
ynh_script_progression --message="Starting a systemd service..." --weight=4
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2022-03-06 19:01:21 +01:00
|
|
|
ynh_systemd_action --service_name=uwsgi-app@$app.service --action=start --line_match="spawned uWSGI master process" --log_path="/var/log/uwsgi/$app/$app.log"
|
2018-05-11 22:59:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# GENERIC FINALIZATION
|
2018-05-11 22:59:18 +02:00
|
|
|
#=================================================
|
2022-03-06 19:01:21 +01:00
|
|
|
# RELOAD NGINX
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reloading NGINX web server..." --weight=2
|
2018-05-11 22:59:18 +02:00
|
|
|
|
2022-03-06 19:01:21 +01:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-03-03 20:33:02 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2022-06-29 01:07:32 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|