define containerName once

This commit is contained in:
Asif Bacchus 2019-09-10 17:22:43 -06:00
parent bbbdf38dcc
commit a26bb36f17
2 changed files with 19 additions and 39 deletions

View File

@ -1,19 +1,3 @@
{ {
"bookmarks": [ "bookmarks": []
{
"fsPath": "$ROOTPATH$/root/scripts/backup.sh",
"bookmarks": [
-1,
478,
225,
-1,
-1,
-1,
-1,
-1,
-1,
-1
]
}
]
} }

View File

@ -225,29 +225,25 @@ function cleanup {
### operate docker containers ### operate docker containers
function operateDocker { function operateDocker {
# determine action to take containerName="$(docker ps --format '{{ .Names }}' --filter name=${COMPOSE_PROJECT_NAME}_${2}-mailcow_1)"
if [ "$1" = "stop" ]; then
containerName="$(docker ps --format '{{.Names}}' --filter name=${COMPOSE_PROJECT_NAME}_${2}-mailcow_1)"
echo -e "${op}[$(stamp)] Stopping ${2}-mailcow container...${normal}" \ # determine action to take
>> "$logFile" if [ "$1" = "stop" ]; then
docker-compose stop --timeout ${dockerStopTimeout} ${2}-mailcow \ echo -e "${op}[$(stamp)] Stopping ${2}-mailcow container...${normal}" \
2>> "$logFile" >> "$logFile"
# verify container stopped (should return true) docker-compose stop --timeout ${dockerStopTimeout} ${2}-mailcow \
dockerResultState=$(docker inspect -f '{{ .State.Running }}' \ 2>> "$logFile"
$containerName) # verify container stopped (should return true)
# verify clean stop (exit code 0) dockerResultState="$(docker inspect -f '{{ .State.Running }}' $containerName)"
dockerResultExit=$(docker inspect -f '{{ .State.ExitCode }}' \ # verify clean stop (exit code 0)
$containerName) dockerResultExit="$(docker inspect -f '{{ .State.ExitCode }}' $containerName)"
elif [ "$1" = "start" ]; then elif [ "$1" = "start" ]; then
echo -e "${op}[$(stamp)] Starting ${2}-mailcow container...${normal}" \ echo -e "${op}[$(stamp)] Starting ${2}-mailcow container...${normal}" \
>> "$logFile" >> "$logFile"
docker-compose start ${2}-mailcow 2>> "$logFile" docker-compose start ${2}-mailcow 2>> "$logFile"
# verify # verify
containerName="$(docker ps --format '{{.Names}}' --filter name=${COMPOSE_PROJECT_NAME}_${2}-mailcow_1)" dockerResultState="$(docker inspect -f '{{ .State.Running }}' $containerName)"
dockerResultState=$(docker inspect -f '{{ .State.Running }}' \ fi
$containerName)
fi
} }
### End of Functions ### ### End of Functions ###