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
|
|
|
|
#=================================================
|
|
|
|
|
2022-05-29 12:45:09 +02:00
|
|
|
ynh_clean_setup () {
|
|
|
|
ynh_clean_check_starting
|
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
|
2020-04-22 16:04:49 +02:00
|
|
|
ynh_abort_if_errors
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# LOAD SETTINGS
|
|
|
|
#=================================================
|
2022-05-29 12:45:09 +02:00
|
|
|
ynh_script_progression --message="Loading installation settings..."
|
2020-04-22 16:04:49 +02:00
|
|
|
|
|
|
|
app=$YNH_APP_INSTANCE_NAME
|
|
|
|
|
|
|
|
domain=$(ynh_app_setting_get --app=$app --key=domain)
|
|
|
|
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
|
|
|
|
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
|
|
|
|
db_user=$db_name
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# CHECK IF THE APP CAN BE RESTORED
|
|
|
|
#=================================================
|
2020-05-03 13:38:04 +02:00
|
|
|
ynh_script_progression --message="Validating restoration parameters..."
|
2020-04-22 16:04:49 +02:00
|
|
|
|
|
|
|
test ! -d $final_path \
|
|
|
|
|| ynh_die --message="There is already a directory: $final_path "
|
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
|
|
|
# RESTORE THE NGINX CONFIGURATION
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Restoring the NGINX web server configuration..."
|
2020-05-17 15:56:54 +02:00
|
|
|
|
2022-05-29 12:45:09 +02:00
|
|
|
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
|
|
|
# RECREATE THE DEDICATED USER
|
2020-05-17 15:56:54 +02:00
|
|
|
#=================================================
|
2022-05-29 12:45:09 +02:00
|
|
|
ynh_script_progression --message="Recreating the dedicated system user..."
|
2020-12-18 22:56:28 +01:00
|
|
|
|
2022-05-29 12:45:09 +02:00
|
|
|
# Create the dedicated user (if not existing)
|
2022-06-04 16:51:38 +02:00
|
|
|
ynh_system_user_create --username=$app --home_dir="$final_path"
|
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-05-29 12:45:09 +02:00
|
|
|
ynh_script_progression --message="Restoring the app main directory..."
|
|
|
|
|
|
|
|
ynh_restore_file --origin_path="$final_path"
|
|
|
|
|
|
|
|
chmod 750 "$final_path"
|
|
|
|
chmod -R o-rwx "$final_path"
|
|
|
|
chown -R $app:www-data "$final_path"
|
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
|
|
|
|
#=================================================
|
|
|
|
ynh_script_progression --message="Reinstalling dependencies..." --weight=5
|
|
|
|
|
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies $build_pkg_dependencies
|
|
|
|
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-05-29 12:45:09 +02:00
|
|
|
# RESTORE THE POSTGRESQL DATABASE
|
2020-05-17 15:56:54 +02:00
|
|
|
#=================================================
|
2022-05-29 12:45:09 +02:00
|
|
|
ynh_script_progression --message="Restoring the PostgreSQL database..."
|
2020-05-17 15:56:54 +02:00
|
|
|
|
2022-05-29 12:45:09 +02:00
|
|
|
ynh_psql_test_if_first_run
|
2022-06-01 08:23:40 +02:00
|
|
|
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
|
2022-05-29 12:45:09 +02:00
|
|
|
ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
|
|
|
|
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
|
|
|
|
|
|
|
|
pushd $final_path/live
|
|
|
|
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
|
|
|
|
2022-05-29 12:57:08 +02:00
|
|
|
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
|
|
|
|
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-05-29 12:45:09 +02:00
|
|
|
ynh_script_progression --message="Restoring the systemd configuration..."
|
|
|
|
|
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-05-29 12:45:09 +02:00
|
|
|
ynh_script_progression --message="Integrating service in YunoHost..."
|
2020-12-18 22:56:28 +01:00
|
|
|
|
2022-05-29 12:45:09 +02:00
|
|
|
yunohost service add $app.target \
|
|
|
|
--log $final_path/live/log/production.log \
|
|
|
|
$final_path/live/log/unicorn-stderr.log\
|
|
|
|
$final_path/live/log/unicorn-stdout.log\
|
|
|
|
$final_path/live/log/sidekiq.log\
|
|
|
|
--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-05-29 12:45:09 +02:00
|
|
|
ynh_script_progression --message="Starting a systemd service..."
|
2020-12-18 22:56:28 +01:00
|
|
|
|
2022-05-29 12:45:09 +02:00
|
|
|
systemctl restart ${app}.target
|
|
|
|
ynh_systemd_action --service_name=${app}_web.service --action=restart --log_path="$final_path/live/log/production.log" --line_match="successfully configured the federation library"
|
|
|
|
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-05-29 12:45:09 +02:00
|
|
|
ynh_script_progression --message="Reloading NGINX web server..."
|
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
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
ynh_script_progression --message="Restoration completed for $app"
|