#!/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 ../settings/scripts/ynh_add_swap source /usr/share/yunohost/helpers #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression "Restoring the app main directory..." ynh_restore "$install_dir" #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= ynh_script_progression "Restoring the PostgreSQL database..." ynh_psql_db_shell <<< "ALTER USER $db_user CREATEDB;" ynh_psql_db_shell < "./db.sql" #================================================= # ADD SWAP IF NEEDED #================================================= ynh_script_progression "Adding swap if needed..." total_memory=$(ynh_get_ram --total) swap_needed=0 if [ $total_memory -lt $memory_needed ]; then # Need a minimum of 8Go of memory swap_needed=$(($memory_needed - $total_memory)) fi ynh_script_progression "Adding $swap_needed Mo to swap..." ynh_add_swap --size=$swap_needed #================================================= # BUILD APP #================================================= ynh_script_progression "Building app..." pushd "$install_dir/live" gem update --system gem install bundler --no-document ynh_hide_warnings ynh_exec_as_app $ld_preload bin/bundle install --redownload -j$(getconf _NPROCESSORS_ONLN) popd #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= ynh_script_progression "Restoring system configurations related to $app..." ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" ynh_restore "/etc/systemd/system/$app-web.service" ynh_restore "/etc/systemd/system/$app-sidekiq.service" ynh_restore "/etc/systemd/system/$app-streaming.service" systemctl enable "$app-web" "$app-sidekiq" "$app-streaming" --quiet 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" ynh_restore "/etc/cron.d/$app" mkdir -p /var/log/$app ynh_restore "/etc/logrotate.d/$app" #================================================= # RELOAD NGINX AND THE APP SERVICE #================================================= ynh_script_progression "Reloading NGINX web server and $app's service..." 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" ynh_systemctl --service=nginx --action=reload #================================================= # END OF SCRIPT #================================================= ynh_script_progression "Restoration completed for $app"