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

142 lines
5.3 KiB
Text
Raw Normal View History

2017-02-13 20:43:41 +01:00
#!/bin/bash
2018-01-30 23:44:49 +01:00
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
2019-04-30 19:15:33 +02:00
#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source ../settings/scripts/experimental_helper.sh
source /usr/share/yunohost/helpers
2017-02-13 20:43:41 +01:00
2019-04-30 19:15:33 +02:00
#=================================================
# LOAD SETTINGS
#=================================================
ynh_script_progression --message="Loading settings..."
#=================================================
# RECREATE THE DEDICATED USER
#=================================================
ynh_script_progression --message="Recreating the dedicated system user..." --weight=3
# Create the dedicated user (if not existing)
yunohost user create $YNH_APP_ID -F "Synapse Application" -d $domain -p "$synapse_user_app_pwd"
adduser $YNH_APP_ID ssl-cert
adduser turnserver ssl-cert
2023-11-01 19:25:19 +01:00
#=================================================
# FIX DB CONFIG
#=================================================
ynh_script_progression --message="Fixing database type..." --weight=1
ynh_psql_execute_as_root \
--sql="update pg_database set datcollate='C', datctype='C' where datname='$db_name';"
2019-04-30 19:15:33 +02:00
#=================================================
2019-06-01 21:37:12 +02:00
# RESTORE ALL CONFIG AND DATA
2018-01-30 23:44:49 +01:00
#=================================================
2019-06-01 21:37:12 +02:00
ynh_script_progression --message="Restoring directory and configuration..." --weight=10
ynh_restore
mkdir -p /etc/matrix-$app/app-service
2019-02-08 11:24:08 +01:00
# Check that the good python version is installed
# If not upgrade the source
2020-08-01 14:17:33 +02:00
ynh_script_progression --message="Check for source up to date..." --weight=5
install_sources
2019-04-30 19:15:33 +02:00
#=================================================
# RESTORE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Reload Fail2Ban..." --weight=6
2023-08-26 12:07:09 +02:00
2019-04-30 19:15:33 +02:00
ynh_systemd_action --action=restart --service_name=fail2ban
2019-02-08 11:24:08 +01:00
2019-04-30 19:15:33 +02:00
#=================================================
# RESTORE THE POSTGRESQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=13
2019-04-30 19:15:33 +02:00
ynh_psql_execute_file_as_root --file="${YNH_CWD}/dump.sql" --database="$synapse_db_name"
#=================================================
# RESTORE SYSTEMD
#=================================================
2019-06-01 21:37:12 +02:00
ynh_script_progression --message="Enable systemd services" --weight=2
2019-04-30 19:15:33 +02:00
# systemctl daemon-reload
systemctl enable matrix-$app.service --quiet
systemctl enable coturn-$app.service --quiet
2019-04-30 19:15:33 +02:00
#=================================================
# ADVERTISE SERVICE IN ADMIN PANEL
#=================================================
yunohost service add matrix-$app --log "/var/log/matrix-$app/homeserver.log" --needs_exposed_ports $port_synapse_tls
yunohost service add coturn-$app --needs_exposed_ports $port_turnserver_tls
2019-04-30 19:15:33 +02:00
#=================================================
# CREATE A DH FILE
#=================================================
ynh_script_progression --message="Creating a dh file..." --weight=40
# WARNING : theses command are used in INSTALL, UPGRADE, RESTORE
# For any update do it in all files
# Make dh cert for synapse if it doesn't exist
if [ ! -e /etc/ssl/private/dh2048.pem ]
then
ynh_exec_warn_less openssl dhparam -out /etc/ssl/private/dh2048.pem -outform PEM -2 2048 -dsaparam
chown root:ssl-cert /etc/ssl/private/dh2048.pem
chmod 640 /etc/ssl/private/dh2048.pem
fi
#=================================================
# RECONFIGURE THE TURNSERVER
#=================================================
ynh_script_progression --message="Reconfiguring Coturn..." --weight=23
configure_coturn
2018-01-30 23:44:49 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
# SETUP LOGROTATE
2018-01-30 23:44:49 +01:00
#=================================================
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Configuring log rotation..."
2018-01-30 23:44:49 +01:00
2019-09-30 10:37:22 +02:00
ynh_use_logrotate --logfile /var/log/matrix-$app
2018-01-30 23:44:49 +01:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# SECURE FILES AND DIRECTORIES
#=================================================
ynh_script_progression --message="Protecting directories..." --weight=3
set_permissions
2018-01-30 23:44:49 +01:00
#=================================================
# RELOAD NGINX, SYNAPSE AND COTURN
#=================================================
ynh_script_progression --message="Restarting Synapse services..." --weight=7
2018-01-30 23:44:49 +01:00
2019-04-30 19:15:33 +02:00
ynh_systemd_action --service_name=coturn-$app.service --action=restart
ynh_systemd_action --service_name=matrix-$app --action=restart --line_match="Synapse now listening on TCP port $port_synapse_tls" --log_path="/var/log/matrix-$app/homeserver.log" --timeout=300
2019-04-30 19:15:33 +02:00
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..."
2019-04-30 19:15:33 +02:00
ynh_systemd_action --service_name=php$phpversion-fpm --action=reload
2019-04-30 19:15:33 +02:00
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# END OF SCRIPT
#=================================================
2018-03-13 16:50:27 +01:00
2019-04-30 19:15:33 +02:00
ynh_script_progression --message="Restoration completed for $app" --last