1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/nextcloud_ynh.git synced 2024-09-03 19:55:57 +02:00
nextcloud_ynh/scripts/restore
Kayou d7d24034cf
Add notify push option (#417)
* add notify_push option

* self-test notify_push

* fix notify_app

* new permission hpb, some fixes

* fix the restore script

* fix restore²

* fix upgrade

* fix socket path

* Update doc/DISCLAIMER_fr.md

* split nginx conf

* use official helpers with modified args

* Auto-update READMEs

* update nginx conf, add new services

* add tests

* add arch var

* tests: enable_notify_push is false by default

* fix upgrade

* final_path -> install_dir

* fix socket nginx path

* add notify_push nginx conf before, so the reload in ynh_add_nginx_config load it

* fully functional version

* readd a removed fix

* run cron task after notify push setup

* Auto-update READMEs

* remove systemd files

* add notify push in config panel

* add cron again because to make notify push happy

* fix indent

* enable/disable the notify push path

* fix path unit

* exec only for nextcloud user

* move sock file to /var/run

* start notify-push after the watcher

* ²

* remove warning

* cron can sometimes fail when the database is not fully initialized, retries the cron job several times and catch catch the error on failure

* oupsie

* Apply suggestions from code review

Co-authored-by: eric_G <46165813+ericgaspar@users.noreply.github.com>

---------

Co-authored-by: Éric Gaspar <46165813+ericgaspar@users.noreply.github.com>
Co-authored-by: yunohost-bot <yunohost@yunohost.org>
2024-08-27 14:52:11 +02:00

184 lines
7.2 KiB
Bash
Executable file

#!/bin/bash
source ../settings/scripts/_common.sh
source /usr/share/yunohost/helpers
source ../settings/scripts/_ynh_mysql_connect_as.sh
#=================================================
# STANDARD RESTORATION STEPS
#=================================================
# RESTORE THE APP MAIN DIR
#=================================================
ynh_script_progression --message="Restoring the app main directory..."
ynh_restore_file --origin_path="$install_dir"
#=================================================
# RESTORE THE MYSQL DATABASE
#=================================================
ynh_script_progression --message="Restoring the MySQL database..." --weight=9
ynh_mysql_connect_as --user=$db_name --password=$db_pwd --database=$db_name --default_character_set="utf8mb4" < ./db.sql
#=================================================
# RESTORE THE PHP-FPM CONFIGURATION
#=================================================
ynh_script_progression --message="Reconfiguring PHP-FPM..." --weight=50
# Restore the file first, so it can have a backup if different
ynh_restore_file --origin_path="/etc/php/$phpversion/fpm/pool.d/$app.conf"
# Recreate a dedicated PHP-FPM config
ynh_add_fpm_config
#=================================================
# RESTORE THE NGINX CONFIGURATION
#=================================================
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.d"
# Check if .well-known is available for this domain
if is_url_handled --domain="$domain" --path="/.well-known/caldav" || is_url_handled --domain="$domain" --path="/.well-known/carddav"
then
ynh_print_warn --message="Another app already uses the domain $domain to serve a CalDAV/CardDAV feature. You may encounter issues when dealing with your calendar or address book."
# Remove lines about .well-known/CardDAV and CalDAV with sed.
sed --in-place --regexp-extended '/location = \/\.well\-known\/(caldav|carddav)/d' "/etc/nginx/conf.d/$domain.d/$app.conf"
fi
#=================================================
# RESTORE THE CRON FILE
#=================================================
ynh_script_progression --message="Restoring cron job..." --weight=1
ynh_restore_file --origin_path="/etc/cron.d/$app"
#=================================================
# RESTORE LOGS
#=================================================
ynh_restore_file --origin_path="/var/log/$app"
#=================================================
# BACKUP THE LOGROTATE CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1
ynh_restore_file --origin_path="/etc/logrotate.d/$app"
#=================================================
# RESTORE THE DATA DIRECTORY
#=================================================
ynh_script_progression --message="Restoring data directory..." --weight=2
# Use --not_mandatory for the data directory, because if the backup has been made with BACKUP_CORE_ONLY, there's no data into the backup.
ynh_restore_file --origin_path="$data_dir" --not_mandatory
#=================================================
# RESTORE USER RIGHTS
#=================================================
# Fix app ownerships & permissions
chown -R $app:www-data "$install_dir"
chown -R $app: "$data_dir"
find $install_dir/ -type f -print0 | xargs -r0 chmod 0644
find $install_dir/ -type d -print0 | xargs -r0 chmod 0755
find $data_dir/data/ -type f -print0 | xargs -r0 chmod 0640
find $data_dir/data/ -type d -print0 | xargs -r0 chmod 0750
chmod 600 "$install_dir/config/config.php"
chmod 755 /home/yunohost.app
chmod 750 $install_dir
# Iterate over users to extend their home folder permissions - for the external
# storage plugin usage - and create relevant Nextcloud directories
for u in $(ynh_user_list); do
mkdir -p "$data_dir/$u"
setfacl --modify g:$app:rwx "/home/$u" || true
done
#=================================================
# YUNOHOST MULTIMEDIA INTEGRATION
#=================================================
ynh_script_progression --message="Adding multimedia directories..." --weight=4
# Build YunoHost multimedia directories
ynh_multimedia_build_main_dir
# Allow nextcloud to write into these directories
ynh_multimedia_addaccess $app
#=================================================
# RESTORE THE FAIL2BAN CONFIGURATION
#=================================================
ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=7
ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf"
ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf"
# Make sure a log file exists (mostly for CI tests)
logfile="/var/log/$app/nextcloud.log"
if [ ! -f "$logfile" ]; then
touch "$logfile"
chown "$app:" "$logfile"
fi
ynh_systemd_action --action=restart --service_name=fail2ban
#=================================================
# RESTORE THE NOTIFY_PUSH APP
#=================================================
if [ $enable_notify_push -eq 1 ]
then
mkdir -p /var/run/$app/
chown $app: /var/run/$app/
ynh_restore_file --origin_path="/etc/systemd/system/${app}-notify-push.service"
ynh_restore_file --origin_path="/etc/systemd/system/${app}-notify-push-watcher.service"
ynh_restore_file --origin_path="/etc/systemd/system/${app}-notify-push-watcher.path"
systemctl enable --now "${app}-notify-push-watcher.service" --quiet
systemctl enable --now "${app}-notify-push-watcher.path" --quiet
systemctl enable --now "${app}-notify-push.service" --quiet
fi
#=================================================
# GENERIC FINALIZATION
#=================================================
# RELOAD NGINX
#=================================================
ynh_script_progression --message="Reloading NGINX web server..." --weight=3
ynh_systemd_action --service_name=nginx --action=reload
#=================================================
# CHECK IF NOTIFY_PUSH WORKS
#=================================================
exec_occ() {
(cd "$install_dir" && ynh_exec_as "$app" \
php${phpversion} --define apc.enable_cli=1 occ --no-interaction --no-ansi "$@")
}
if [ $enable_notify_push -eq 1 ]
then
count=0
while ! ynh_exec_as "$app" php${phpversion} --define apc.enable_cli=1 $install_dir/cron.php && [[ $count -lt 30 ]]
do
sleep 1
count=$((count + 1))
done
ynh_systemd_action --service_name="${app}-notify-push-watcher" --action=restart
ynh_systemd_action --service_name="${app}-notify-push" --action=restart --line_match="Push daemon for Nextcloud clients." --log_path="systemd" --action=restart
if ! exec_occ notify_push:self-test; then
ynh_print_warn --message="The High Performance Backend service is still not working properly. Please log in with a user to your NextCloud instance, restart the High Performance Backend service with \"systemctl restart ${app}-notify-push.service\", and run \"sudo -u $app php${phpversion} $install_dir/occ notify_push:self-test\" to verify that everything is green."
fi
fi
#=================================================
# END OF SCRIPT
#=================================================
ynh_script_progression --message="Restoration completed for $app" --last