1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/diaspora_ynh.git synced 2024-09-03 18:26:13 +02:00
diaspora_ynh/scripts/restore

164 lines
6.4 KiB
Text
Raw Normal View History

2020-04-22 16:04:49 +02:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2022-05-29 12:45:09 +02:00
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
2020-05-17 15:56:54 +02:00
source ../settings/scripts/_common.sh
2022-05-29 12:45:09 +02:00
source ../settings/scripts/ynh_install_ruby__2
2020-04-22 16:04:49 +02:00
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2024-02-29 10:11:40 +01:00
#REMOVEME? ynh_clean_setup () {
2022-09-26 02:56:12 +02:00
true
2020-07-05 19:14:29 +02:00
}
2022-05-29 12:45:09 +02:00
# Exit if an error occurs during the execution of the script
2024-02-29 10:11:40 +01:00
#REMOVEME? ynh_abort_if_errors
2020-04-22 16:04:49 +02:00
#=================================================
# LOAD SETTINGS
#=================================================
2024-02-29 10:11:40 +01:00
#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1
2020-04-22 16:04:49 +02:00
2024-02-29 10:11:40 +01:00
#REMOVEME? app=$YNH_APP_INSTANCE_NAME
2020-04-22 16:04:49 +02:00
2024-02-29 10:11:40 +01:00
#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain)
#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir)
#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name)
#REMOVEME? db_user=$db_name
2020-04-22 16:04:49 +02:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2024-02-29 10:11:40 +01:00
#REMOVEME? ynh_script_progression --message="Validating restoration parameters..." --weight=1
2020-04-22 16:04:49 +02:00
2024-02-29 10:11:40 +01:00
#REMOVEME? test ! -d $install_dir \
|| ynh_die --message="There is already a directory: $install_dir "
2020-05-17 15:56:54 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# STANDARD RESTORATION STEPS
2020-05-17 15:56:54 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# RECREATE THE DEDICATED USER
2020-05-17 15:56:54 +02:00
#=================================================
2024-02-29 10:11:40 +01:00
#REMOVEME? ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
2020-12-18 22:56:28 +01:00
2022-05-29 12:45:09 +02:00
# Create the dedicated user (if not existing)
2024-02-29 10:11:40 +01:00
#REMOVEME? ynh_system_user_create --username=$app --home_dir="$install_dir"
2020-05-17 15:56:54 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# RESTORE THE APP MAIN DIR
2020-05-17 15:56:54 +02:00
#=================================================
2022-09-26 02:56:12 +02:00
ynh_script_progression --message="Restoring the app main directory..." --weight=1
2022-05-29 12:45:09 +02:00
2024-02-29 10:11:40 +01:00
ynh_restore_file --origin_path="$install_dir"
2022-05-29 12:45:09 +02:00
2024-02-29 10:11:40 +01:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
2020-05-17 15:56:54 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# SPECIFIC RESTORATION
2020-05-17 15:56:54 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# REINSTALL DEPENDENCIES
#=================================================
2024-02-29 10:11:40 +01:00
#REMOVEME? ynh_script_progression --message="Reinstalling dependencies..." --weight=5
2022-05-29 12:45:09 +02:00
2024-02-29 10:11:40 +01:00
#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies $build_pkg_dependencies
2022-05-29 12:45:09 +02:00
ynh_exec_warn_less ynh_install_ruby --ruby_version=$ruby_version
ynh_exec_warn_less ynh_install_nodejs --nodejs_version=$nodejs_version
2020-05-17 15:56:54 +02:00
2022-09-26 02:56:12 +02:00
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2020-05-17 15:56:54 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# RESTORE THE POSTGRESQL DATABASE
2020-05-17 15:56:54 +02:00
#=================================================
2024-02-29 10:11:40 +01:00
#REMOVEME? ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=1
2020-05-17 15:56:54 +02:00
2024-02-29 10:11:40 +01:00
#REMOVEME? ynh_psql_test_if_first_run
#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
#REMOVEME? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
2022-05-29 12:45:09 +02:00
ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name"
2020-05-17 15:56:54 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# BUILD APP
2020-05-17 15:56:54 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
ynh_script_progression --message="Building app..." --weight=40
2024-02-29 10:11:40 +01:00
pushd $install_dir/live
2022-05-29 12:45:09 +02:00
ynh_use_ruby
ynh_use_nodejs
ynh_gem install bundler:$bundler_version
ynh_exec_as $app $ynh_ruby_load_path $ld_preload script/configure_bundler
popd
2020-05-17 15:56:54 +02:00
2024-02-29 10:11:40 +01:00
#REMOVEME? ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
2022-05-29 12:57:08 +02:00
ynh_package_autoremove
2020-05-17 15:56:54 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# RESTORE SYSTEMD
2020-05-17 15:56:54 +02:00
#=================================================
2022-09-26 02:56:12 +02:00
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
2022-05-29 12:45:09 +02:00
2022-05-29 12:57:08 +02:00
ynh_restore_file --origin_path="/etc/systemd/system/${app}_web.service"
ynh_restore_file --origin_path="/etc/systemd/system/${app}_sidekiq.service"
# tmp files
2022-06-04 16:51:38 +02:00
install -T --mode=0644 -v ../settings/conf/diaspora.tmpfiles.d /etc/tmpfiles.d/${app}.conf
2022-05-29 12:57:08 +02:00
ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file=/etc/tmpfiles.d/${app}.conf
# target unit
2022-06-04 16:51:38 +02:00
install -T --mode=0644 -v ../settings/conf/diaspora.target /etc/systemd/system/${app}.target
2022-05-29 12:57:08 +02:00
ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file=/etc/systemd/system/${app}.target
# reload, create, enable and start stuff
systemctl daemon-reload
systemd-tmpfiles --create
2022-06-07 23:23:47 +02:00
systemctl enable "${app}_web" "${app}_sidekiq" "$app.target" --quiet
2020-05-17 15:56:54 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# INTEGRATE SERVICE IN YUNOHOST
2020-05-17 15:56:54 +02:00
#=================================================
2022-09-26 02:56:12 +02:00
ynh_script_progression --message="Integrating service in YunoHost..." --weight=1
2020-12-18 22:56:28 +01:00
2022-05-29 12:45:09 +02:00
yunohost service add $app.target \
2024-02-29 10:11:40 +01:00
--log $install_dir/live/log/production.log \
$install_dir/live/log/unicorn-stderr.log\
$install_dir/live/log/unicorn-stdout.log\
$install_dir/live/log/sidekiq.log\
2022-05-29 12:45:09 +02:00
--description "Diaspora service (unicorn web and sidekiq)"
2020-05-17 15:56:54 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# START SYSTEMD SERVICE
2020-05-17 15:56:54 +02:00
#=================================================
2022-09-26 02:56:12 +02:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2020-12-18 22:56:28 +01:00
2022-05-29 12:45:09 +02:00
systemctl restart ${app}.target
2024-02-29 10:11:40 +01:00
ynh_systemd_action --service_name=${app}_web.service --action=restart --log_path="$install_dir/live/log/production.log" --line_match="successfully configured the federation library"
2022-05-29 12:45:09 +02:00
ynh_systemd_action --service_name=${app}_sidekiq.service --action=restart --log_path="systemd" --line_match="Running in ruby"
2020-05-17 15:56:54 +02:00
#=================================================
2022-05-29 12:45:09 +02:00
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
2020-05-17 15:56:54 +02:00
#=================================================
2022-09-26 02:56:12 +02:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2020-12-18 22:56:28 +01:00
2022-05-29 12:45:09 +02:00
ynh_systemd_action --service_name=nginx --action=reload
2020-05-17 15:56:54 +02:00
2022-05-29 12:45:09 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2022-09-26 02:56:12 +02:00
ynh_script_progression --message="Restoration completed for $app" --last