mirror of
https://github.com/YunoHost-Apps/acropolis_ynh.git
synced 2024-09-03 18:06:22 +02:00
97 lines
3.5 KiB
Bash
97 lines
3.5 KiB
Bash
#!/bin/bash
|
|
|
|
#=================================================
|
|
# IMPORT GENERIC HELPERS
|
|
#=================================================
|
|
|
|
# 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_ruby
|
|
source ../settings/scripts/ynh_add_swap
|
|
source /usr/share/yunohost/helpers
|
|
|
|
#=================================================
|
|
# INSTALL DEPENDENCIES
|
|
#=================================================
|
|
ynh_script_progression --message="Reinstalling Ruby..." --weight=4
|
|
|
|
ynh_exec_warn_less ynh_install_ruby --ruby_version="$RUBY_VERSION"
|
|
|
|
#=================================================
|
|
# ADD SWAP IF NEEDED
|
|
#=================================================
|
|
ynh_script_progression --message="Adding swap if needed..."
|
|
|
|
total_memory=$(ynh_get_ram --total)
|
|
swap_needed=0
|
|
|
|
if (( MEMORY_NEEDED > total_memory )); then
|
|
# Need a minimum of 2.5Go of memory
|
|
swap_needed=$((MEMORY_NEEDED - total_memory))
|
|
fi
|
|
|
|
ynh_script_progression --message="Adding $swap_needed Mo to swap..."
|
|
ynh_add_swap --size=$swap_needed
|
|
|
|
#=================================================
|
|
# RESTORE THE APP MAIN DIR
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the app main directory..." --weight=1
|
|
|
|
ynh_restore_file --origin_path="$install_dir"
|
|
|
|
mkdir -p "$install_dir/tmp/pids"
|
|
|
|
chmod -R o-rwx "$install_dir"
|
|
chown -R "$app:$app" "$install_dir"
|
|
|
|
#=================================================
|
|
# RESTORE THE POSTGRESQL DATABASE
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
|
|
|
|
ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql
|
|
|
|
#=================================================
|
|
# INSTALLING RUBY AND BUNDLER
|
|
#=================================================
|
|
ynh_script_progression --message="Rebuilding $app..."
|
|
|
|
pushd "$install_dir"
|
|
ynh_use_ruby
|
|
ynh_gem install bundler:1.17.3 --no-document
|
|
ynh_exec_as "$app" echo "gem: --no-ri --no-rdoc" >> "$install_dir/.gemrc"
|
|
popd
|
|
|
|
#=================================================
|
|
# RESTORE SYSTEM CONFIGURATIONS
|
|
#=================================================
|
|
ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1
|
|
|
|
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
|
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app-web.service"
|
|
systemctl enable "$app-web" --quiet
|
|
yunohost service add "$app-web" --description="$app web service"
|
|
|
|
ynh_restore_file --origin_path="/etc/systemd/system/$app-sidekiq.service"
|
|
systemctl enable "$app-sidekiq" --quiet
|
|
yunohost service add "$app-sidekiq" --description="$app sidekiq service"
|
|
|
|
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
|
|
|
|
#=================================================
|
|
# RELOAD NGINX AND PHP-FPM OR THE APP SERVICE
|
|
#=================================================
|
|
ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1
|
|
|
|
ynh_systemd_action --service_name="${app}-web" --action="start" --log_path=systemd --line_match="listening on"
|
|
ynh_systemd_action --service_name="${app}-sidekiq" --action="start" --log_path=systemd --line_match="Booted Rails"
|
|
|
|
ynh_systemd_action --service_name=nginx --action=reload
|
|
|
|
#=================================================
|
|
# END OF SCRIPT
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoration completed for $app" --last
|