seafile_ynh/scripts/restore

102 lines
3.3 KiB
Text
Raw Normal View History

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
2017-07-21 14:56:41 +02:00
# Source YunoHost helpers
source /usr/share/yunohost/helpers
2017-01-28 18:51:23 +01:00
2017-07-21 14:56:41 +02:00
# Stop script if errors
ynh_abort_if_errors
2017-01-28 18:51:23 +01:00
2017-07-21 14:56:41 +02:00
# Import common cmd
source ../settings/scripts/experimental_helper.sh
2017-07-21 14:56:41 +02:00
source ../settings/scripts/_common.sh
2017-02-28 13:24:18 +01:00
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Loading settings..."
2017-01-05 23:24:32 +01:00
# Retrieve arguments
2019-06-11 22:28:26 +02:00
domain=$(ynh_app_setting_get --app $app --key domain)
path_url=$(ynh_normalize_url_path $(ynh_app_setting_get --app $app --key path))
2017-12-15 23:12:34 +01:00
seafile_data=/home/yunohost.app/seafile-data
2019-06-11 22:28:26 +02:00
db_pwd=$(ynh_app_setting_get --app $app --key mysqlpwd)
final_path=$(ynh_app_setting_get --app $app --key final_path)
seafile_user=$app
# Check domain/path availability
2019-06-11 22:28:26 +02:00
ynh_webpath_available $domain $path_url || ynh_die --message "$domain/$path_url is not available, please use an other domain or path."
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
2017-07-21 14:56:41 +02:00
# Restore all config and data
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Restoring files..." --weight=10
2017-07-21 14:56:41 +02:00
ynh_restore
# Create user
2019-09-10 22:50:07 +02:00
ynh_script_progression --message="Configuring system user..."
ynh_system_user_create $seafile_user $final_path
2017-12-10 10:45:51 +01:00
2019-05-07 21:52:43 +02:00
# Restore dependencies
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Reinstalling dependencies..." --weight=5
2019-05-07 21:52:43 +02:00
install_dependance
# Restore mysql dump
2019-09-10 22:50:07 +02:00
ynh_script_progression --message="Restoring database..." --weight=3
2019-06-11 22:28:26 +02:00
db_user=seafile
ynh_mysql_setup_db --db_user $db_user --db_name ccnetdb --db_pwd "$db_pwd"
ynh_mysql_setup_db --db_user $db_user --db_name seafiledb --db_pwd "$db_pwd"
ynh_mysql_setup_db --db_user $db_user --db_name seahubdb --db_pwd "$db_pwd"
2017-07-21 14:56:41 +02:00
su -c "mysql -u ${app} -p$db_pwd ccnetdb < ${YNH_CWD}/ccnetdb.dmp"
su -c "mysql -u ${app} -p$db_pwd seafiledb < ${YNH_CWD}/seafiledb.dmp"
su -c "mysql -u ${app} -p$db_pwd seahubdb < ${YNH_CWD}/seahubdb.dmp"
2016-02-08 02:06:58 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
2016-02-08 02:06:58 +01:00
# Restore sso persistent config
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Configuring permissions..."
python3 ../settings/conf/add_sso_conf.py || ynh_die --message="Your file /etc/ssowat/conf.json.persistent doesn't respect the json syntax. Please fix the syntax to install this app."
2017-07-21 14:56:41 +02:00
# Add logrotate
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Configuring log rotation..."
ynh_use_logrotate $final_path/logs
2017-12-15 23:12:34 +01:00
ln -s $final_path/logs /var/log/seafile
2019-06-11 22:28:26 +02:00
# Set all permissions
ynh_script_progression --message="Protecting directory..."
set_permission
2019-06-12 22:56:50 +02:00
# Enable service and start seafile
ynh_script_progression --message="Reconfiguring application..."
systemctl daemon-reload
systemctl enable seafile
systemctl enable seahub
# Add Seafile to YunoHost's monitored services
2019-09-10 22:50:07 +02:00
ynh_script_progression --message="Register seafile service..."
2019-06-11 22:28:26 +02:00
yunohost service add seafile
yunohost service add seahub
2019-06-12 22:56:50 +02:00
ynh_script_progression --message="Reloading services..."
2017-07-21 14:56:41 +02:00
# Reload nginx
systemctl reload nginx.service
2019-06-12 22:56:50 +02:00
# Reload fail2ban
ynh_systemd_action --service_name=fail2ban --action=reload
# Avoid the current effect
sleep 5
# Restart service
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Starting seafile services..." --weight=3
ynh_systemd_action --service_name seafile
ynh_systemd_action --service_name seahub
2019-08-05 17:08:29 +02:00
sleep 5
2019-06-11 22:28:26 +02:00
ynh_script_progression --message="Restoration completed for $app" --last