1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mattermost_ynh.git synced 2024-09-03 19:36:29 +02:00
mattermost_ynh/scripts/restore

155 lines
5.3 KiB
Text
Raw Normal View History

2017-09-11 12:05:16 +02:00
#!/bin/bash
2021-01-11 23:46:48 +01:00
#=================================================
# GENERIC START
2017-09-11 12:05:16 +02:00
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2021-01-11 23:46:48 +01:00
source ../settings/scripts/_common.sh
2017-09-11 12:05:16 +02:00
source /usr/share/yunohost/helpers
#=================================================
# MANAGE SCRIPT FAILURE
#=================================================
2021-01-11 23:46:48 +01:00
ynh_clean_setup () {
ynh_clean_check_starting
}
# Exit if an error occurs during the execution of the script
ynh_abort_if_errors
2017-09-11 12:05:16 +02:00
#=================================================
# LOAD SETTINGS
#=================================================
2021-01-11 23:46:48 +01:00
ynh_script_progression --message="Loading installation settings..." --weight=1
2017-09-11 12:05:16 +02:00
app=$YNH_APP_INSTANCE_NAME
2021-01-11 23:46:48 +01:00
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)
port=$(ynh_app_setting_get --app=$app --key=port)
db_name=$(ynh_app_setting_get --app=$app --key=db_name)
db_user=$db_name
2021-09-16 11:39:20 +02:00
data_path=$(ynh_app_setting_get --app=$app --key=data_path)
2017-09-11 12:05:16 +02:00
#=================================================
# CHECK IF THE APP CAN BE RESTORED
#=================================================
2021-01-11 23:46:48 +01:00
ynh_script_progression --message="Validating restoration parameters..." --weight=1
2017-09-11 12:05:16 +02:00
test ! -d $final_path \
2021-01-11 23:46:48 +01:00
|| ynh_die --message="There is already a directory: $final_path "
2017-09-11 12:05:16 +02:00
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
2022-06-22 11:09:45 +02:00
ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1
2017-09-11 12:05:16 +02:00
2021-01-11 23:46:48 +01:00
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
2017-09-11 12:05:16 +02:00
2021-09-16 11:39:20 +02:00
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=1
# Create the dedicated user (if not existing)
ynh_system_user_create --username=$app --home_dir="$final_path"
2017-09-11 12:05:16 +02:00
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
2021-01-11 23:46:48 +01:00
ynh_script_progression --message="Restoring the app main directory..." --weight=2
2017-09-11 12:05:16 +02:00
2021-01-11 23:46:48 +01:00
ynh_restore_file --origin_path="$final_path"
2017-09-11 12:05:16 +02:00
2021-09-16 11:39:20 +02:00
chmod 750 "$final_path"
chmod -R o-rwx "$final_path"
chown -R $app:www-data "$final_path"
2017-09-11 12:05:16 +02:00
#=================================================
2021-09-16 11:39:20 +02:00
# RESTORE THE DATA DIRECTORY
#=================================================
2021-09-16 11:39:20 +02:00
ynh_script_progression --message="Restoring the data directory..." --weight=4
2021-09-16 11:39:20 +02:00
ynh_restore_file --origin_path="$data_path" --not_mandatory
2021-09-16 11:39:20 +02:00
mkdir -p $data_path
2017-09-11 12:05:16 +02:00
2021-09-16 11:39:20 +02:00
chmod 750 "$data_path"
chmod -R o-rwx "$data_path"
chown -R $app:www-data "$data_path"
2017-09-11 12:05:16 +02:00
#=================================================
2022-06-22 10:58:12 +02:00
# REINSTALL DEPENDENCIES
2017-09-11 12:05:16 +02:00
#=================================================
2022-06-22 10:58:12 +02:00
ynh_script_progression --message="Reinstalling dependencies..." --weight=10
2017-09-11 12:05:16 +02:00
2022-06-22 10:58:12 +02:00
# Define and install dependencies
ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies
#=================================================
# RESTORE THE DATABASE
#=================================================
ynh_script_progression --message="Restoring the database..." --weight=6
db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd)
ynh_psql_test_if_first_run
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
2017-09-11 12:05:16 +02:00
#=================================================
# RESTORE USER RIGHTS
#=================================================
2021-01-11 23:46:48 +01:00
logs_path="/var/log/$app"
mkdir -p $logs_path
chown -R $app: $logs_path
2017-10-10 12:47:33 +02:00
2017-09-11 12:05:16 +02:00
#=================================================
# SPECIFIC RESTORATION
#=================================================
# RESTORE SYSTEMD
2017-09-11 12:05:16 +02:00
#=================================================
ynh_restore_file "/etc/systemd/system/$app.service"
2021-01-11 23:46:48 +01:00
systemctl enable $app.service --quiet
2017-09-11 12:05:16 +02:00
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
2021-01-11 23:46:48 +01:00
yunohost service add $app --description="Collaboration platform built for developers" --log="/var/log/$app/$app.log"
#=================================================
# START SYSTEMD SERVICE
#=================================================
ynh_script_progression --message="Starting a systemd service..." --weight=2
# Start a systemd service
ynh_systemd_action --service_name=$app --action=start --log_path=systemd --line_match="Started Mattermost"
2021-01-11 23:46:48 +01:00
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
2017-09-11 12:05:16 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
2017-10-12 08:08:53 +02:00
# RELOAD NGINX
2017-09-11 12:05:16 +02:00
#=================================================
2021-01-11 23:46:48 +01:00
ynh_script_progression --message="Reloading NGINX web server..." --weight=1
2017-09-11 12:05:16 +02:00
2021-01-11 23:46:48 +01:00
ynh_systemd_action --service_name=nginx --action=reload
2017-10-12 08:08:53 +02:00
#=================================================
2021-01-11 23:46:48 +01:00
# END OF SCRIPT
2017-10-12 08:08:53 +02:00
#=================================================
2021-01-11 23:46:48 +01:00
ynh_script_progression --message="Restoration completed for $app" --last