1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mattermost_ynh.git synced 2024-09-03 19:36:29 +02:00

Merge pull request #92 from YunoHost-Apps/fix-upgrade-failure

upgrade: attempt to restore backup only if it was correctly saved
This commit is contained in:
Pierre de La Morinerie 2018-02-05 10:49:12 +05:30 committed by GitHub
commit 652c3a8251
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -36,16 +36,32 @@ logs_path="/var/log/$app"
#================================================= #=================================================
# Backup the current version of the app # Backup the current version of the app
ynh_backup_before_upgrade # (NB: `tee` uses process substitution rather than a pipe,
# to avoid spawning a subshell that would not save global
# variables defined by `ynh_backup_before_upgrade`.)
ynh_backup_before_upgrade > >(tee "upgrade.log")
# Ensure the backup can be restored
if grep -q "mattermost: Warning$" "upgrade.log"; then
can_restore_backup=false
else
can_restore_backup=true
fi
# If the upgrade fails… # If the upgrade fails…
ynh_clean_setup () { ynh_clean_setup () {
# Stop attempting to restart the app if [ "$can_restore_backup" = true ]; then
if $(sudo systemctl -q is-active "$app"); then # Stop attempting to restart the app
sudo systemctl stop "$app" if $(sudo systemctl -q is-active "$app"); then
sudo systemctl stop "$app"
fi
# Restore the backup
ynh_restore_upgradebackup
else
# Backup restoration is not available:
# let's try at least to restart the server.
sudo systemctl start "$app"
fi fi
# Restore the backup
ynh_restore_upgradebackup
} }
# Exit if an error occurs during the execution of the script # Exit if an error occurs during the execution of the script