2017-04-10 02:55:10 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2021-04-09 22:18:53 +00:00
|
|
|
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
|
2019-03-19 22:16:12 +00:00
|
|
|
source ../settings/scripts/_common.sh
|
2019-08-11 13:58:52 +00:00
|
|
|
source ../settings/scripts/ynh_add_swap
|
2019-04-06 14:08:48 +00:00
|
|
|
source /usr/share/yunohost/helpers
|
2018-05-01 18:43:05 +00:00
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# STANDARD RESTORATION STEPS
|
|
|
|
|
#=================================================
|
2021-04-09 22:18:53 +00:00
|
|
|
# RESTORE THE APP MAIN DIR
|
2018-05-01 18:43:05 +00:00
|
|
|
#=================================================
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_script_progression "Restoring the app main directory..."
|
2021-04-09 22:18:53 +00:00
|
|
|
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_restore "$install_dir"
|
2022-09-19 23:57:06 +00:00
|
|
|
|
2022-01-07 00:25:26 +00:00
|
|
|
#=================================================
|
|
|
|
|
# RESTORE THE POSTGRESQL DATABASE
|
|
|
|
|
#=================================================
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_script_progression "Restoring the PostgreSQL database..."
|
2022-01-07 00:25:26 +00:00
|
|
|
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_psql_db_shell <<< "ALTER USER $db_user CREATEDB;"
|
2025-08-25 06:42:42 +00:00
|
|
|
ynh_psql_db_shell < "./db.sql"
|
2022-01-07 00:25:26 +00:00
|
|
|
|
2019-08-11 13:58:52 +00:00
|
|
|
#=================================================
|
|
|
|
|
# ADD SWAP IF NEEDED
|
|
|
|
|
#=================================================
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_script_progression "Adding swap if needed..."
|
2019-08-11 13:58:52 +00:00
|
|
|
|
2020-05-26 11:18:02 +00:00
|
|
|
total_memory=$(ynh_get_ram --total)
|
2019-08-11 13:58:52 +00:00
|
|
|
swap_needed=0
|
|
|
|
|
|
2022-05-29 13:54:35 +00:00
|
|
|
if [ $total_memory -lt $memory_needed ]; then
|
2019-08-11 13:58:52 +00:00
|
|
|
# Need a minimum of 8Go of memory
|
2022-05-29 13:54:35 +00:00
|
|
|
swap_needed=$(($memory_needed - $total_memory))
|
2019-08-11 13:58:52 +00:00
|
|
|
fi
|
|
|
|
|
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_script_progression "Adding $swap_needed Mo to swap..."
|
2024-02-24 22:28:27 +00:00
|
|
|
|
2019-08-11 13:58:52 +00:00
|
|
|
ynh_add_swap --size=$swap_needed
|
|
|
|
|
|
2024-02-24 22:28:27 +00:00
|
|
|
#=================================================
|
|
|
|
|
# REINSTALL DEPENDENCIES
|
|
|
|
|
#=================================================
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_script_progression "Reinstalling Ruby and NodeJS..."
|
2024-02-24 22:28:27 +00:00
|
|
|
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_ruby_install
|
|
|
|
|
ynh_nodejs_install
|
2024-02-24 22:28:27 +00:00
|
|
|
|
2019-04-06 14:08:48 +00:00
|
|
|
#=================================================
|
2022-05-29 13:54:35 +00:00
|
|
|
# BUILD APP
|
2019-04-06 14:08:48 +00:00
|
|
|
#=================================================
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_script_progression "Building app..."
|
2019-03-21 19:34:35 +00:00
|
|
|
|
2024-02-24 22:28:27 +00:00
|
|
|
pushd "$install_dir/live"
|
2025-08-21 08:42:04 +00:00
|
|
|
gem update --system
|
|
|
|
|
gem install bundler --no-document
|
2025-08-29 19:49:53 +00:00
|
|
|
ynh_exec_as_app LD_PRELOAD=libjemalloc.so bin/bundle install --redownload -j$(getconf _NPROCESSORS_ONLN)
|
2020-05-18 23:20:45 +00:00
|
|
|
popd
|
2019-03-21 19:34:35 +00:00
|
|
|
|
2018-05-01 18:43:05 +00:00
|
|
|
#=================================================
|
2024-02-24 22:28:27 +00:00
|
|
|
# RESTORE SYSTEM CONFIGURATIONS
|
2018-05-01 18:43:05 +00:00
|
|
|
#=================================================
|
2024-02-24 22:28:27 +00:00
|
|
|
# RESTORE THE PHP-FPM CONFIGURATION
|
2018-05-01 18:43:05 +00:00
|
|
|
#=================================================
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_script_progression "Restoring system configurations related to $app..."
|
2024-02-24 22:28:27 +00:00
|
|
|
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
|
2018-05-01 18:43:05 +00:00
|
|
|
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_restore "/etc/systemd/system/$app-web.service"
|
|
|
|
|
ynh_restore "/etc/systemd/system/$app-sidekiq.service"
|
|
|
|
|
ynh_restore "/etc/systemd/system/$app-streaming.service"
|
2021-02-17 18:22:07 +00:00
|
|
|
systemctl enable "$app-web" "$app-sidekiq" "$app-streaming" --quiet
|
2018-05-01 18:43:05 +00:00
|
|
|
|
2021-04-09 22:18:53 +00:00
|
|
|
yunohost service add "$app-web" --description="$app web service"
|
|
|
|
|
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
|
|
|
|
|
yunohost service add "$app-streaming" --description="$app streaming service"
|
2018-06-21 02:48:02 +00:00
|
|
|
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_restore "/etc/cron.d/$app"
|
2018-11-07 04:12:21 +00:00
|
|
|
|
2024-02-24 22:28:27 +00:00
|
|
|
mkdir -p /var/log/$app
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_restore "/etc/logrotate.d/$app"
|
2018-11-07 04:12:21 +00:00
|
|
|
|
2019-04-06 14:08:48 +00:00
|
|
|
#=================================================
|
2024-02-24 22:28:27 +00:00
|
|
|
# RELOAD NGINX AND THE APP SERVICE
|
2018-05-01 18:43:05 +00:00
|
|
|
#=================================================
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_script_progression "Reloading NGINX web server and $app's service..."
|
2024-02-24 22:28:27 +00:00
|
|
|
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_systemctl --service=${app}-web --action="start" --log_path=/var/log/$app/$app-web.log --wait_until="Listening on"
|
|
|
|
|
ynh_systemctl --service=${app}-sidekiq --action="start" --log_path=/var/log/$app/$app-sidekiq.log --wait_until="Schedules Loaded"
|
|
|
|
|
ynh_systemctl --service=${app}-streaming --action="start" --log_path=/var/log/$app/$app-streaming.log --wait_until="Streaming API now listening"
|
2018-05-01 18:43:05 +00:00
|
|
|
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_systemctl --service=nginx --action=reload
|
2019-03-18 03:22:38 +00:00
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
|
# END OF SCRIPT
|
|
|
|
|
#=================================================
|
|
|
|
|
|
2025-08-21 08:42:04 +00:00
|
|
|
ynh_script_progression "Restoration completed for $app"
|