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

166 lines
7.6 KiB
Text
Raw Permalink Normal View History

2022-04-19 20:31:41 +02:00
#!/bin/bash
# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
2023-11-28 12:00:27 +01:00
#=================================================
# INSTALL DEPENDENCIES
#=================================================
2024-06-27 20:48:13 +02:00
ynh_nodejs_install
2023-11-28 12:00:27 +01:00
ynh_install_mongo
2023-11-27 16:55:13 +01:00
#=================================================
# CREATE A MONGODB DATABASE
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Creating a MongoDB database..."
2023-11-27 16:55:13 +01:00
db_name=$(ynh_sanitize_dbid --db_name=$app)
db_user=$db_name
2024-06-27 20:48:13 +02:00
ynh_app_setting_set --key=db_name --value=$db_name
2023-11-27 16:55:13 +01:00
ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name
2024-02-15 15:34:35 +01:00
#=================================================
# SPECIFIC SETUP
#=================================================
# CONFIGURE MONGOD
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Configuring MongoDB..."
2024-02-15 15:34:35 +01:00
2024-06-27 20:48:13 +02:00
ynh_replace --match="#replication:" --replace="replication:\n replSetName: rs0" --file="/etc/mongod.conf"
2024-02-15 15:34:35 +01:00
2024-06-27 20:48:13 +02:00
ynh_hide_warnings systemctl enable mongod --quiet
ynh_systemctl --service=mongod --action=restart --log_path=/var/log/mongodb/mongod.log --wait_until="Waiting for connections"
2024-02-15 15:34:35 +01:00
2024-06-27 20:48:13 +02:00
if ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.status())" | grep -q "no replset config has been received"; then
ynh_hide_warnings ynh_mongo_exec --command="printjson(rs.initiate())" --eval
2024-02-15 15:34:35 +01:00
fi
2022-04-19 20:31:41 +02:00
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Restoring the NGINX web server configuration..."
2022-04-19 20:31:41 +02:00
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf"
2022-04-19 20:31:41 +02:00
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Restoring the app main directory..."
2022-04-19 20:31:41 +02:00
2024-06-27 20:48:13 +02:00
ynh_restore "$install_dir"
2022-04-19 20:31:41 +02:00
2023-11-19 16:41:50 +01:00
chmod 750 "$install_dir"
chmod -R o-rwx "$install_dir"
chown -R $app:www-data "$install_dir"
2022-04-19 20:31:41 +02:00
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Restoring the data directory..."
2022-04-19 20:31:41 +02:00
2024-06-27 20:48:13 +02:00
ynh_restore "$data_dir"
2022-04-19 20:31:41 +02:00
2023-11-19 16:41:50 +01:00
chmod 750 "$data_dir"
chmod -R o-rwx "$data_dir"
chown -R $app:www-data "$data_dir"
2022-04-19 20:31:41 +02:00
#=================================================
2022-04-23 19:59:10 +02:00
# RESTORE THE MONGODB DATABASE
2022-04-19 20:31:41 +02:00
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Restoring the MongoDB database..."
2022-04-19 20:31:41 +02:00
2024-06-27 20:48:13 +02:00
db_pwd=$(ynh_app_setting_get --key=db_pwd)
2022-04-23 19:59:10 +02:00
ynh_mongo_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd
2024-06-27 20:48:13 +02:00
ynh_mongo_restore_db < ./dump.bson
2022-04-19 20:31:41 +02:00
#=================================================
# RESTORE SYSTEMD
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Restoring $app's systemd service..."
2022-04-19 20:31:41 +02:00
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/systemd/system/$app-chat.service"
2022-04-23 19:59:10 +02:00
systemctl enable $app-chat.service --quiet
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/systemd/system/$app-clsi.service"
2022-04-23 19:59:10 +02:00
systemctl enable $app-clsi.service --quiet
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/systemd/system/$app-contacts.service"
2022-04-23 19:59:10 +02:00
systemctl enable $app-contacts.service --quiet
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/systemd/system/$app-docstore.service"
2022-04-23 19:59:10 +02:00
systemctl enable $app-docstore.service --quiet
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/systemd/system/$app-document-updater.service"
2022-04-23 19:59:10 +02:00
systemctl enable $app-document-updater.service --quiet
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/systemd/system/$app-filestore.service"
2022-04-23 19:59:10 +02:00
systemctl enable $app-filestore.service --quiet
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/systemd/system/$app-history-v1.service"
2023-11-22 15:12:51 +01:00
systemctl enable $app-history-v1.service --quiet
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/systemd/system/$app-notifications.service"
2022-04-23 19:59:10 +02:00
systemctl enable $app-notifications.service --quiet
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/systemd/system/$app-project-history.service"
2023-11-22 15:12:51 +01:00
systemctl enable $app-project-history.service --quiet
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/systemd/system/$app-real-time.service"
2022-04-23 19:59:10 +02:00
systemctl enable $app-real-time.service --quiet
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/systemd/system/$app-spelling.service"
2022-04-23 19:59:10 +02:00
systemctl enable $app-spelling.service --quiet
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/systemd/system/$app-web.service"
2022-04-23 19:59:10 +02:00
systemctl enable $app-web.service --quiet
2022-04-19 20:31:41 +02:00
#=================================================
# RESTORE THE LOGROTATE CONFIGURATION
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Restoring the logrotate configuration..."
2022-04-19 20:31:41 +02:00
2022-04-23 19:59:10 +02:00
mkdir -p "/var/log/$app"
chown -R $app:$app "/var/log/$app"
2024-06-27 20:48:13 +02:00
ynh_restore "/etc/logrotate.d/$app"
2022-04-19 20:31:41 +02:00
#=================================================
# INTEGRATE SERVICE IN YUNOHOST
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Integrating service in YunoHost..."
2022-04-19 20:31:41 +02:00
2022-04-23 19:59:10 +02:00
yunohost service add "$app-chat" --log="/var/log/$app/chat.log"
yunohost service add "$app-clsi" --log="/var/log/$app/clsi.log"
yunohost service add "$app-contacts" --log="/var/log/$app/contacts.log"
yunohost service add "$app-docstore" --log="/var/log/$app/docstore.log"
yunohost service add "$app-document-updater" --log="/var/log/$app/document-updater.log"
yunohost service add "$app-filestore" --log="/var/log/$app/filestore.log"
2023-11-22 15:12:51 +01:00
yunohost service add "$app-history-v1" --log="/var/log/$app/history-v1.log"
2022-04-23 19:59:10 +02:00
yunohost service add "$app-notifications" --log="/var/log/$app/notifications.log"
2023-11-22 15:12:51 +01:00
yunohost service add "$app-project-history" --log="/var/log/$app/project-history.log"
2022-04-23 19:59:10 +02:00
yunohost service add "$app-real-time" --log="/var/log/$app/real-time.log"
yunohost service add "$app-spelling" --log="/var/log/$app/spelling.log"
yunohost service add "$app-web" --log="/var/log/$app/web.log"
2022-04-19 20:31:41 +02:00
#=================================================
# START SYSTEMD SERVICE
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Starting $app's systemd service..."
2022-04-19 20:31:41 +02:00
2024-06-27 20:48:13 +02:00
ynh_systemctl --service="$app-chat" --action="start" --log_path="/var/log/$app/chat.log" --wait_until="Using settings from"
ynh_systemctl --service="$app-clsi" --action="start" --log_path="/var/log/$app/clsi.log" --wait_until="Using settings from"
ynh_systemctl --service="$app-contacts" --action="start" --log_path="/var/log/$app/contacts.log" --wait_until="Using settings from"
ynh_systemctl --service="$app-docstore" --action="start" --log_path="/var/log/$app/docstore.log" --wait_until="Using settings from"
ynh_systemctl --service="$app-document-updater" --action="start" --log_path="/var/log/$app/document-updater.log" --wait_until="Using settings from"
ynh_systemctl --service="$app-filestore" --action="start" --log_path="/var/log/$app/filestore.log" --wait_until="Using settings from"
ynh_systemctl --service="$app-history-v1" --action="start" --log_path="/var/log/$app/history-v1.log" --wait_until="Loading backend"
ynh_systemctl --service="$app-notifications" --action="start" --log_path="/var/log/$app/notifications.log" --wait_until="Using settings from"
ynh_systemctl --service="$app-project-history" --action="start" --log_path="/var/log/$app/project-history.log" --wait_until="Using settings from"
ynh_systemctl --service="$app-real-time" --action="start" --log_path="/var/log/$app/real-time.log" --wait_until="Using settings from"
ynh_systemctl --service="$app-spelling" --action="start" --log_path="/var/log/$app/spelling.log" --wait_until="Using settings from"
ynh_systemctl --service="$app-web" --action="start" --log_path="/var/log/$app/web.log" --wait_until="listening on" --wait_until="Using settings from"
2022-04-19 20:31:41 +02:00
#=================================================
2022-04-23 19:59:10 +02:00
# RELOAD NGINX
2022-04-19 20:31:41 +02:00
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Reloading NGINX web server..."
2022-04-19 20:31:41 +02:00
2024-06-27 20:48:13 +02:00
ynh_systemctl --service=nginx --action=reload
2022-04-19 20:31:41 +02:00
#=================================================
# END OF SCRIPT
#=================================================
2024-06-27 20:48:13 +02:00
ynh_script_progression "Restoration completed for $app"