From 6fb1a19f0ca61ff97fc744ec0b3214105e38959f Mon Sep 17 00:00:00 2001 From: ronivay Date: Sat, 28 Jul 2018 16:49:13 +0300 Subject: [PATCH] Improve error handling --- xo-install.sh | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/xo-install.sh b/xo-install.sh index f97f669..dcf8158 100755 --- a/xo-install.sh +++ b/xo-install.sh @@ -45,10 +45,22 @@ function CheckUser { } +function ErrorHandling { + + echo "Something went wrong, exiting. Check $LOGFILE for more details and use rollback feature if needed" + + if [[ -d $INSTALLDIR/xo-builds/xen-orchestra-$TIME ]]; then + echo "Removing $INSTALLDIR/xo-builds/xen-orchestra-$TIME because of failed installation." + rm -rf $INSTALLDIR/xo-builds/xen-orchestra-$TIME + fi +} + function InstallDependenciesCentOS { set -e + trap ErrorHandling ERR INT + # Install necessary dependencies for XO build # only run automated node install if package not found @@ -92,6 +104,8 @@ function InstallDependenciesDebian { set -e + trap ErrorHandling ERR INT + # Install necessary dependencies for XO build echo @@ -165,6 +179,10 @@ function UpdateNodeYarn { function InstallXOPlugins { + set -e + + trap ErrorHandling ERR INT + if [[ "$PLUGINS" ]] && [[ ! -z "$PLUGINS" ]]; then echo @@ -192,6 +210,8 @@ function InstallXO { set -e + trap ErrorHandling ERR INT + TIME=$(date +%Y%d%m%H%M) # Create user if doesn't exist (if defined) @@ -381,7 +401,7 @@ function HandleArgs { } -function RollBackInstallation { +function RollBackInstallation { INSTALLATIONS=($(find $INSTALLDIR/xo-builds/ -maxdepth 1 -type d -name "xen-orchestra-*")) @@ -417,7 +437,7 @@ function RollBackInstallation { esac done -} 2>$LOGFILE +} function CheckOS {