diff --git a/scripts/upgrade b/scripts/upgrade index c9a46d7..332de9b 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -36,16 +36,32 @@ logs_path="/var/log/$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… ynh_clean_setup () { - # Stop attempting to restart the app - if $(sudo systemctl -q is-active "$app"); then - sudo systemctl stop "$app" + if [ "$can_restore_backup" = true ]; then + # Stop attempting to restart the 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 - # Restore the backup - ynh_restore_upgradebackup } # Exit if an error occurs during the execution of the script