2016-05-07 18:21:06 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC STARTING
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
2016-07-04 21:16:34 +02:00
|
|
|
|
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
|
|
|
|
#=================================================
|
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
|
|
|
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_webpath_available --domain=$domain --path_url=$path_url \
|
|
|
|
|| ynh_die --message="Path not available: ${domain}${path_url}"
|
2017-05-01 15:47:20 +02:00
|
|
|
test ! -d $final_path \
|
2019-05-18 20:15:36 +02:00
|
|
|
|| 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
|
|
|
#=================================================
|
|
|
|
# STANDARD RESTORE STEPS
|
|
|
|
#=================================================
|
|
|
|
# RESTORE OF THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# RESTORE OF THE MAIN DIR OF THE APP
|
|
|
|
#=================================================
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_script_progression --message="Restoring the app main directory..."
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2019-03-03 20:32:26 +01:00
|
|
|
mkdir -p "$(dirname "$final_path")"
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_restore_file --origin_path="$final_path"
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# INSTALL DEPENDENCIES
|
|
|
|
#=================================================
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=35
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2019-04-13 00:38:47 +02:00
|
|
|
ynh_install_app_dependencies $pkg_dependencies
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# RECREATE OF THE DEDICATED USER
|
|
|
|
#=================================================
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_script_progression --message="Recreating the dedicated system user..." --weight=3
|
2017-05-01 15:47:20 +02:00
|
|
|
|
2017-08-28 03:03:36 +02:00
|
|
|
# Create the dedicated user (if not existing)
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_system_user_create --username=$app
|
2017-05-01 15:47:20 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# SPECIFIC RESTORE
|
|
|
|
#=================================================
|
|
|
|
# RESTORE USER RIGHTS
|
|
|
|
#=================================================
|
|
|
|
|
2017-08-28 03:03:36 +02:00
|
|
|
chown $app: --recursive "$final_path"
|
2017-05-01 15:47:20 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# RESTORE THE UWSGI CONFIG
|
|
|
|
#=================================================
|
|
|
|
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_restore_file --origin_path="/etc/uwsgi/apps-available/$app.ini"
|
2020-04-10 22:02:55 +02:00
|
|
|
ynh_restore_file --origin_path "/var/log/uwsgi/$app"
|
|
|
|
chown $app:root /var/log/uwsgi/$app
|
2020-04-11 14:18:51 +02:00
|
|
|
ynh_check_global_uwsgi_config
|
2020-04-10 22:02:55 +02:00
|
|
|
systemctl enable "uwsgi-app@$app.service"
|
2016-07-04 21:16:34 +02:00
|
|
|
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALISATION
|
|
|
|
#=================================================
|
2018-05-11 22:59:18 +02:00
|
|
|
# RELOAD NGINX
|
2017-05-01 15:47:20 +02:00
|
|
|
#=================================================
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_script_progression --message="Reloading nginx web server..."
|
2016-05-07 18:21:06 +02:00
|
|
|
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
2018-05-11 22:59:18 +02:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK SEARX STARTING
|
|
|
|
#=================================================
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_script_progression --message="Starting Searx..." --weight=4
|
2018-05-11 22:59:18 +02:00
|
|
|
|
|
|
|
# Wait for searx to be fully started
|
2020-04-10 22:02:55 +02: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"
|
2019-03-03 20:33:02 +01:00
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# END OF SCRIPT
|
|
|
|
#=================================================
|
|
|
|
|
2019-05-18 20:15:36 +02:00
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|