From 0ff153ef22ab71ad6ca6e31d37f59950062a9545 Mon Sep 17 00:00:00 2001 From: lablans Date: Wed, 8 Mar 2023 09:00:38 +0000 Subject: [PATCH 1/2] Use project name. Add is-running function. --- bridgehead | 7 +++++-- lib/functions.sh | 12 +++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bridgehead b/bridgehead index 227a0d7..60f4aa9 100755 --- a/bridgehead +++ b/bridgehead @@ -66,11 +66,14 @@ case "$ACTION" in checkRequirements hc_send log "Bridgehead $PROJECT startup: Requirements checked out. Now starting bridgehead ..." export LDM_LOGIN=$(getLdmPassword) - exec $COMPOSE -f ./$PROJECT/docker-compose.yml $OVERRIDE up --abort-on-container-exit + exec $COMPOSE -p bridgehead-$PROJECT -f ./$PROJECT/docker-compose.yml $OVERRIDE up --abort-on-container-exit ;; stop) loadVars - exec $COMPOSE -f ./$PROJECT/docker-compose.yml $OVERRIDE down + exec $COMPOSE -p bridgehead-$PROJECT -f ./$PROJECT/docker-compose.yml $OVERRIDE down + ;; + is-running) + exit bk_is_running ;; update) loadVars diff --git a/lib/functions.sh b/lib/functions.sh index 23fb939..6954cd2 100644 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -34,7 +34,7 @@ checkOwner(){ } printUsage() { - echo "Usage: bridgehead start|stop|update|install|uninstall|enroll PROJECTNAME" + echo "Usage: bridgehead start|stop|is-running|update|install|uninstall|enroll PROJECTNAME" echo "PROJECTNAME should be one of ccp|bbmri" } @@ -169,6 +169,16 @@ function retry { return 0 } +function bk_is_running { + RUNNING="$($COMPOSE -p bridgehead-$PROJECT -f ./$PROJECT/docker-compose.yml $OVERRIDE ps -q)" + NUMBEROFRUNNING=$(echo "$RUNNING" | wc -l) + if [ $NUMBEROFRUNNING -gt 0 ]; then + return 0 + else + return 1 + fi +} + ##Setting Network properties # currently not needed #export HOSTIP=$(MSYS_NO_PATHCONV=1 docker run --rm --add-host=host.docker.internal:host-gateway ubuntu cat /etc/hosts | grep 'host.docker.internal' | awk '{print $1}'); From 380511d3bb5ff95422f269621eb49484b231199a Mon Sep 17 00:00:00 2001 From: Martin Lablans Date: Wed, 8 Mar 2023 10:37:37 +0100 Subject: [PATCH 2/2] Don't delete docker images if BK is not running --- bridgehead | 3 ++- lib/functions.sh | 3 ++- lib/update-bridgehead.sh | 9 +++++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/bridgehead b/bridgehead index 60f4aa9..f2eaa6b 100755 --- a/bridgehead +++ b/bridgehead @@ -73,7 +73,8 @@ case "$ACTION" in exec $COMPOSE -p bridgehead-$PROJECT -f ./$PROJECT/docker-compose.yml $OVERRIDE down ;; is-running) - exit bk_is_running + bk_is_running + exit $? ;; update) loadVars diff --git a/lib/functions.sh b/lib/functions.sh index 6954cd2..836ffcc 100644 --- a/lib/functions.sh +++ b/lib/functions.sh @@ -170,9 +170,10 @@ function retry { } function bk_is_running { + detectCompose RUNNING="$($COMPOSE -p bridgehead-$PROJECT -f ./$PROJECT/docker-compose.yml $OVERRIDE ps -q)" NUMBEROFRUNNING=$(echo "$RUNNING" | wc -l) - if [ $NUMBEROFRUNNING -gt 0 ]; then + if [ $NUMBEROFRUNNING -ge 2 ]; then return 0 else return 1 diff --git a/lib/update-bridgehead.sh b/lib/update-bridgehead.sh index c53b731..bce720d 100755 --- a/lib/update-bridgehead.sh +++ b/lib/update-bridgehead.sh @@ -4,10 +4,15 @@ source lib/functions.sh AUTO_HOUSEKEEPING=${AUTO_HOUSEKEEPING:-true} if [ "$AUTO_HOUSEKEEPING" == "true" ]; then - A="Performing automatic maintenance: Cleaning docker images." + A="Performing automatic maintenance: " + if bk_is_running; then + A="$A Cleaning docker images." + docker system prune -a -f + else + A="$A Not cleaning docker images since BK is not running." + fi hc_send log "$A" log INFO "$A" - docker system prune -a -f else log WARN "Automatic housekeeping disabled (variable AUTO_HOUSEKEEPING != \"true\")" fi