2019-02-23 11:06:32 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source ../settings/scripts/_common.sh
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# MANAGE SCRIPT FAILURE
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Exit if an error occurs during the execution of the script
|
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Loading settings..." --time --weight=1
|
2019-02-23 11:06:32 +01:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get $app domain)
|
|
|
|
path_url=$(ynh_app_setting_get $app path)
|
|
|
|
final_path=$(ynh_app_setting_get $app final_path)
|
|
|
|
config_path=$(ynh_app_setting_get $app config_path)
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..." --time --weight=1
|
2019-02-23 11:06:32 +01:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
|
|
|
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
2019-02-23 11:06:32 +01:00
|
|
|
test ! -d $final_path \
|
2019-10-25 11:04:41 +02:00
|
|
|
|| ynh_die --message="There is already a directory: $final_path "
|
2019-02-23 11:06:32 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2019-02-23 11:06:32 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE APP MAIN DIR
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Restoring the app main directory..." --time --weight=1
|
2019-02-23 11:06:32 +01:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_restore_file --origin_path="$final_path"
|
2019-02-23 11:06:32 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RECREATE THE DEDICATED USER
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1
|
2019-02-23 11:06:32 +01:00
|
|
|
|
|
|
|
# Create the dedicated user (if not existing)
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2019-02-23 11:06:32 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORATION
|
|
|
|
#=================================================
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1
|
2019-02-23 11:06:32 +01:00
|
|
|
|
|
|
|
ynh_install_nodejs $nodejs_version
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE CONFIG
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Restoring the config path..." --time --weight=1
|
2019-02-23 11:06:32 +01:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_restore_file --origin_path="$config_path"
|
2019-02-23 11:06:32 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE SYSTEMD
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Restoring the systemd configuration..." --time --weight=1
|
2019-02-23 11:06:32 +01:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
|
2019-02-23 11:06:32 +01:00
|
|
|
systemctl enable $app.service
|
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
#=================================================
|
|
|
|
# ADVERTISE SERVICE IN ADMIN PANEL
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
yunohost service add $app --log "/var/log/$app/$app.log"
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# START SYSTEMD SERVICE
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Starting a systemd service..." --time --weight=1
|
|
|
|
|
|
|
|
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
|
|
|
|
|
2019-02-23 11:06:32 +01:00
|
|
|
#=================================================
|
|
|
|
# RESTORE THE LOGROTATE CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
2019-02-23 11:06:32 +01:00
|
|
|
|
2019-10-25 21:40:17 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE USER RIGHTS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
# Restore permissions to app files
|
|
|
|
chown -R $app: $final_path
|
|
|
|
chown -R $app: $config_path
|
|
|
|
|
2019-02-23 11:06:32 +01:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
# RELOAD NGINX
|
2019-02-23 11:06:32 +01:00
|
|
|
#=================================================
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..." --time --weight=1
|
2019-02-23 11:06:32 +01:00
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2019-02-23 11:06:32 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2019-10-25 11:04:41 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for $app" --time --last
|