From 9f6c532170d4181713e0f2cd86ab0c30e5b32d04 Mon Sep 17 00:00:00 2001 From: szaimen Date: Mon, 15 Aug 2022 14:00:48 +0200 Subject: [PATCH] don't allow the Nextcloud container to start if the update failed Signed-off-by: szaimen --- Containers/borgbackup/backupscript.sh | 5 +++++ Containers/mastercontainer/daily-backup.sh | 4 ++++ Containers/nextcloud/entrypoint.sh | 10 ++++++++++ 3 files changed, 19 insertions(+) diff --git a/Containers/borgbackup/backupscript.sh b/Containers/borgbackup/backupscript.sh index 8bdf0556..269c9312 100644 --- a/Containers/borgbackup/backupscript.sh +++ b/Containers/borgbackup/backupscript.sh @@ -152,6 +152,11 @@ if [ "$BORG_MODE" = backup ]; then # Inform user get_expiration_time echo "Backup finished successfully on $END_DATE_READABLE ($DURATION_READABLE)" + if [ -f "/nextcloud_aio_volumes/nextcloud_aio_nextcloud_data/update.failed" ]; then + echo "However a Nextcloud update failed. So reporting that the backup failed which will skip any update attempt the next time." + echo "Please restore a backup from before the failed Nextcloud update attempt." + exit 1 + fi exit 0 fi diff --git a/Containers/mastercontainer/daily-backup.sh b/Containers/mastercontainer/daily-backup.sh index ac6a4867..09eefec1 100644 --- a/Containers/mastercontainer/daily-backup.sh +++ b/Containers/mastercontainer/daily-backup.sh @@ -69,6 +69,10 @@ if [ "$DAILY_BACKUP" = 1 ]; then while docker ps --format "{{.Names}}" | grep -q "^nextcloud-aio-nextcloud$" && ! nc -z nextcloud-aio-nextcloud 9000; do echo "Waiting for the Nextcloud container to start" sleep 30 + if [ "$(docker inspect nextcloud-aio-nextcloud --format "{{.State.Restarting}}")" = "true" ]; then + echo "Nextcloud container restarting. Skipping this check!" + break + fi done fi sudo -u www-data php /var/www/docker-aio/php/src/Cron/BackupNotification.php diff --git a/Containers/nextcloud/entrypoint.sh b/Containers/nextcloud/entrypoint.sh index 2c4d8c0d..c1c4b7e4 100644 --- a/Containers/nextcloud/entrypoint.sh +++ b/Containers/nextcloud/entrypoint.sh @@ -57,6 +57,14 @@ if [ -f "/var/www/html/lib/versioncheck.php" ] && ! php /var/www/html/lib/versio exit 1 fi +# Do not start the container if the last update failed +if [ -f "/mnt/ncdata/update.failed" ]; then + echo "The last Nextcloud update failed." + echo "Please restore from backup and try again!" + echo "If you do not have a backup in place, you can simply delete the update.failed file in the datadir which will allow the container to start again." + exit 1 +fi + # Skip any update if Nextcloud was just restored if ! [ -f "/mnt/ncdata/skip.update" ]; then if version_greater "$image_version" "$installed_version"; then @@ -213,6 +221,7 @@ if ! [ -f "/mnt/ncdata/skip.update" ]; then #upgrade else + touch "/mnt/ncdata/update.failed" while [ -n "$(pgrep -f cron.php)" ] do echo "Waiting for Nextclouds cronjob to finish..." @@ -226,6 +235,7 @@ if ! [ -f "/mnt/ncdata/skip.update" ]; then exit 1 fi + rm "/mnt/ncdata/update.failed" bash /notify.sh "Nextcloud update to $image_version successful!" "Feel free to inspect the Nextcloud container logs for more info." php /var/www/html/occ app:list | sed -n "/Enabled:/,/Disabled:/p" > /tmp/list_after