From 13cd3ceec9ce0cf58bef354a5b9b1cb6f7b724cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roni=20V=C3=A4yrynen?= Date: Sun, 2 Jan 2022 11:54:37 +0200 Subject: [PATCH] chore: deal with cleanup situation where there might be proxy and xen orchestra installed on same server. we only want to remove inactive installations --- xo-install.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/xo-install.sh b/xo-install.sh index df7edad..157abad 100755 --- a/xo-install.sh +++ b/xo-install.sh @@ -888,9 +888,18 @@ function UpdateXO { # remove old builds. leave as many as defined in PRESERVE variable echo - printprog "Removing old installations. Leaving $PRESERVE latest" - runcmd "find $INSTALLDIR/xo-builds/ -maxdepth 1 -type d -name \"xen-orchestra*\" -printf \"%T@ %p\\n\" | sort -n | cut -d' ' -f2- | head -n -$PRESERVE | xargs -r rm -r" - printok "Removing old installations. Leaving $PRESERVE latest" + printprog "Removing old inactive installations. Leaving $PRESERVE latest" + local INSTALLATIONS="$(runcmd_stdout "find $INSTALLDIR/xo-builds/ -maxdepth 1 -type d -name \"xen-orchestra*\" -printf \"%T@ %p\\n\" | sort -n | cut -d' ' -f2- | head -n -$PRESERVE")" + local XO_SERVER_ACTIVE="$(runcmd_stdout "readlink -e $INSTALLDIR/xo-server")" + local XO_WEB_ACTIVE="$(runcmd_stdout "readlink -e $INSTALLDIR/xo-web")" + local XO_PROXY_ACTIVE="$(runcmd_stdout "readlink -e $INSTALLDIR/xo-proxy")" + + for DELETEABLE in $INSTALLATIONS; do + if [[ "$XO_SERVER_ACTIVE" != "${DELETABLE}"* ]] && [[ "$XO_WEB_ACTIVE" != "${DELETEABLE}"* ]] && [[ "$XO_PROXY_ACTIVE" != "${DELETEABLE}"* ]]; then + runcmd "rm -rf $DELETEABLE" + fi + done + printok "Removing old inactive installations. Leaving $PRESERVE latest" }