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

166 lines
6.1 KiB
Text
Raw Normal View History

2020-01-18 10:28:47 +01:00
#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# 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
2020-12-20 14:22:36 +01:00
source ../settings/scripts/ynh_install_ruby
2020-01-18 10:28:47 +01:00
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
ynh_clean_setup () {
2020-12-27 23:18:55 +01:00
#### Remove this function if there's nothing to clean before calling the remove script.
true
2020-01-18 10:28:47 +01:00
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
#=================================================
# LOAD SETTINGS
#=================================================
2020-12-23 15:19:09 +01:00
ynh_script_progression --message="Loading settings..." --weight=2
2020-01-18 10:28:47 +01:00
app=$YNH_APP_INSTANCE_NAME
domain=$(ynh_app_setting_get --app=$app --key=domain)
path_url=$(ynh_app_setting_get --app=$app --key=path)
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
2020-12-20 14:22:36 +01:00
db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd)
2020-01-18 10:28:47 +01:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2020-12-23 15:19:09 +01:00
ynh_script_progression --message="Validating restoration parameters..." --weight=2
2020-01-18 10:28:47 +01:00
ynh_webpath_available --domain=$domain --path_url=$path_url \
2020-12-27 23:18:55 +01:00
|| ynh_die --message="Path not available: ${domain}${path_url}"
2020-01-18 10:28:47 +01:00
test ! -d $final_path \
2020-12-27 23:18:55 +01:00
|| ynh_die --message="There is already a directory: $final_path "
2020-01-18 10:28:47 +01:00
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
2020-12-23 15:19:09 +01:00
ynh_script_progression --message="Restoring the app main directory..." --weight=1
2020-01-18 10:28:47 +01:00
ynh_restore_file --origin_path="$final_path"
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
2020-12-23 15:19:09 +01:00
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
2020-01-18 10:28:47 +01:00
# Create the dedicated user (if not existing)
2020-12-20 14:22:36 +01:00
ynh_system_user_create --username=$app --home_dir=$final_path
2020-01-18 10:28:47 +01:00
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Restore permissions on app files
2020-12-20 14:22:36 +01:00
chown -R root: $final_path
chown $app: $final_path
2020-12-27 23:18:55 +01:00
mkdir -p "$final_path/live/log"
chown -R $app: "$final_path/live/log/"
mkdir -p "$final_path/live/tmp"
chown -R $app: "$final_path/live/tmp/"
mkdir -p "/var/log/$app"
chown -R $app: "/var/log/$app"
2020-01-18 10:28:47 +01:00
#=================================================
# SPECIFIC RESTORATION
#=================================================
# REINSTALL DEPENDENCIES
#=================================================
2020-12-24 12:11:42 +01:00
ynh_script_progression --message="Reinstalling dependencies..." --weight=17
2020-01-18 10:28:47 +01:00
# Define and install dependencies
ynh_install_app_dependencies $pkg_dependencies
2020-12-20 14:22:36 +01:00
#=================================================
2020-12-23 15:19:09 +01:00
# INSTALLING RUBY
2020-12-20 14:22:36 +01:00
#=================================================
2020-12-27 23:18:55 +01:00
ynh_script_progression --message="Installing Ruby...( This may take a while... )" --weight=100 #331
2020-12-20 14:22:36 +01:00
ynh_install_ruby --ruby_version=$RUBY_VERSION
/opt/rbenv/versions/$RUBY_VERSION/bin/gem update --system --no-document
2020-01-18 10:28:47 +01:00
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
2020-12-23 15:19:09 +01:00
ynh_script_progression --message="Restoring the MySQL database..." --weight=2
2020-01-18 10:28:47 +01:00
ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
ynh_mysql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql
#=================================================
# RESTORE SYSTEMD
#=================================================
2020-12-23 15:19:09 +01:00
ynh_script_progression --message="Restoring the systemd configuration..." --weight=1
2020-01-18 10:28:47 +01:00
ynh_restore_file --origin_path="/etc/systemd/system/$app.service"
2020-12-24 12:11:42 +01:00
systemctl enable $app.service --quiet
2020-01-18 10:28:47 +01:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
2020-12-24 12:11:42 +01:00
ynh_script_progression --message="Integrate $app service in Yunohost..." --weight=1
2020-01-18 10:28:47 +01:00
2020-12-20 14:22:36 +01:00
yunohost service add $app --description "Standard Notes - Syncing Server" --log "/var/log/$app/$app.log"
2020-01-18 10:28:47 +01:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2020-12-23 15:19:09 +01:00
ynh_script_progression --message="Starting a systemd service..." --weight=1
2020-01-18 10:28:47 +01:00
ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log"
2021-01-07 17:41:34 +01:00
sleep 15
2020-01-18 10:28:47 +01:00
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
2020-12-24 12:11:42 +01:00
ynh_script_progression --message="Configuring log rotation..." --weight=1
2020-01-18 10:28:47 +01:00
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
2021-01-02 19:42:20 +01:00
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
2021-01-03 15:45:28 +01:00
ynh_script_progression --message="Restoring the fail2ban configuration..." --weight=1
2021-01-02 19:42:20 +01:00
touch "/var/log/$app/$app.log"
ynh_restore_file "/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file "/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --action=restart --service_name=fail2ban
2020-01-18 10:28:47 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
2020-12-23 15:19:09 +01:00
# RELOAD NGINX
2020-01-18 10:28:47 +01:00
#=================================================
2020-12-23 15:19:09 +01:00
ynh_script_progression --message="Reloading nginx web server..." --weight=2
2020-01-18 10:28:47 +01:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2020-12-23 15:19:09 +01:00
ynh_script_progression --message="Restoration completed for $app" --last