From a26bb36f176f55dd72c7df63d0dfddcb928ae24d Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Tue, 10 Sep 2019 17:22:43 -0600 Subject: [PATCH] define containerName once --- .vscode/numbered-bookmarks.json | 18 +-------------- root/scripts/backup.sh | 40 +++++++++++++++------------------ 2 files changed, 19 insertions(+), 39 deletions(-) diff --git a/.vscode/numbered-bookmarks.json b/.vscode/numbered-bookmarks.json index fd9f564..4c08963 100644 --- a/.vscode/numbered-bookmarks.json +++ b/.vscode/numbered-bookmarks.json @@ -1,19 +1,3 @@ { - "bookmarks": [ - { - "fsPath": "$ROOTPATH$/root/scripts/backup.sh", - "bookmarks": [ - -1, - 478, - 225, - -1, - -1, - -1, - -1, - -1, - -1, - -1 - ] - } - ] + "bookmarks": [] } \ No newline at end of file diff --git a/root/scripts/backup.sh b/root/scripts/backup.sh index efec532..3be654b 100755 --- a/root/scripts/backup.sh +++ b/root/scripts/backup.sh @@ -225,29 +225,25 @@ function cleanup { ### operate docker containers function operateDocker { -# determine action to take -if [ "$1" = "stop" ]; then - containerName="$(docker ps --format '{{.Names}}' --filter name=${COMPOSE_PROJECT_NAME}_${2}-mailcow_1)" + containerName="$(docker ps --format '{{ .Names }}' --filter name=${COMPOSE_PROJECT_NAME}_${2}-mailcow_1)" - echo -e "${op}[$(stamp)] Stopping ${2}-mailcow container...${normal}" \ - >> "$logFile" - docker-compose stop --timeout ${dockerStopTimeout} ${2}-mailcow \ - 2>> "$logFile" - # verify container stopped (should return true) - dockerResultState=$(docker inspect -f '{{ .State.Running }}' \ - $containerName) - # verify clean stop (exit code 0) - dockerResultExit=$(docker inspect -f '{{ .State.ExitCode }}' \ - $containerName) -elif [ "$1" = "start" ]; then - echo -e "${op}[$(stamp)] Starting ${2}-mailcow container...${normal}" \ - >> "$logFile" - docker-compose start ${2}-mailcow 2>> "$logFile" - # verify - containerName="$(docker ps --format '{{.Names}}' --filter name=${COMPOSE_PROJECT_NAME}_${2}-mailcow_1)" - dockerResultState=$(docker inspect -f '{{ .State.Running }}' \ - $containerName) -fi + # determine action to take + if [ "$1" = "stop" ]; then + echo -e "${op}[$(stamp)] Stopping ${2}-mailcow container...${normal}" \ + >> "$logFile" + docker-compose stop --timeout ${dockerStopTimeout} ${2}-mailcow \ + 2>> "$logFile" + # verify container stopped (should return true) + dockerResultState="$(docker inspect -f '{{ .State.Running }}' $containerName)" + # verify clean stop (exit code 0) + dockerResultExit="$(docker inspect -f '{{ .State.ExitCode }}' $containerName)" + elif [ "$1" = "start" ]; then + echo -e "${op}[$(stamp)] Starting ${2}-mailcow container...${normal}" \ + >> "$logFile" + docker-compose start ${2}-mailcow 2>> "$logFile" + # verify + dockerResultState="$(docker inspect -f '{{ .State.Running }}' $containerName)" + fi } ### End of Functions ###