2022-04-29 12:18:34 +02:00
#!/bin/bash
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
2024-06-23 08:56:30 +02:00
db_name=$(ynh_app_setting_get --key=db_name)
2023-02-20 00:08:32 +01:00
2022-04-29 12:18:34 +02:00
#=================================================
# STANDARD RESTORATION STEPS
2023-03-06 13:32:00 +01:00
#=================================================
# RESTORE LOGROTATE
#=================================================
2024-06-23 08:56:30 +02:00
ynh_script_progression "Configuring logrotate to manage application logfiles"
2023-03-06 13:32:00 +01:00
# Use logrotate to manage application logfile(s)
2024-06-23 08:56:30 +02:00
ynh_config_add_logrotate
2022-04-29 12:18:34 +02:00
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
2024-06-23 08:56:30 +02:00
ynh_script_progression "Restoring the NGINX web server configuration..."
2022-04-29 12:18:34 +02:00
2024-06-23 08:56:30 +02:00
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
2022-04-29 12:18:34 +02:00
2023-02-20 00:08:32 +01:00
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
2024-06-23 08:56:30 +02:00
ynh_script_progression "Restoring the PostgreSQL database..."
2023-02-20 00:08:32 +01:00
2024-06-23 08:56:30 +02:00
ynh_psql_db_shell < "./db.sql"
2023-02-20 00:08:32 +01:00
2022-04-29 12:18:34 +02:00
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
2024-06-23 08:56:30 +02:00
ynh_script_progression "Restoring the app main directory..."
2022-04-29 12:18:34 +02:00
2024-06-23 08:56:30 +02:00
ynh_restore "$install_dir"
2024-08-30 22:54:39 +02:00
#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 $install_dir/.env
2022-04-29 12:18:34 +02:00
2024-08-30 22:54:39 +02:00
#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app: "$install_dir"
2022-04-29 12:18:34 +02:00
#=================================================
# RESTORE SYSTEMD
#=================================================
2024-06-23 08:56:30 +02:00
ynh_script_progression "Restoring $app's systemd service..."
2022-04-29 12:18:34 +02:00
2024-06-23 08:56:30 +02:00
ynh_restore "/etc/systemd/system/${app}.service"
ynh_restore "/etc/systemd/system/${app}_workers.service"
2022-12-31 18:14:15 +01:00
2023-03-02 20:37:23 +01:00
systemctl enable "${app}.service" --quiet
systemctl enable "${app}_workers.service" --quiet
2022-04-29 12:18:34 +02:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
2024-06-23 08:56:30 +02:00
ynh_script_progression "Integrating service in YunoHost..."
2022-04-29 12:18:34 +02:00
2023-09-04 20:14:34 +02:00
yunohost service add "${app}" --description="Fittrackee main service" --log="/var/log/$app/$app.log"
2023-03-08 21:40:21 +01:00
yunohost service add "${app}_workers" --description="Fittrackee task queue service" --log="var/log/$app/${app}_workers.log"
2022-04-29 12:18:34 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2024-06-23 08:56:30 +02:00
ynh_script_progression "Starting $app's systemd service..."
2022-04-29 12:18:34 +02:00
2024-06-23 08:56:30 +02:00
ynh_systemctl --service="${app}" --action="start"
ynh_systemctl --service="${app}_workers" --action="start"
2022-04-29 12:18:34 +02:00
#=================================================
2022-12-21 17:01:09 +01:00
# RELOAD NGINX
2022-04-29 12:18:34 +02:00
#=================================================
2024-06-23 08:56:30 +02:00
ynh_script_progression "Reloading NGINX web server..."
2022-04-29 12:18:34 +02:00
2024-06-23 08:56:30 +02:00
ynh_systemctl --service=nginx --action=reload
2022-04-29 12:18:34 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2024-06-23 08:56:30 +02:00
ynh_script_progression "Restoration completed for $app"