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,28 +225,24 @@ function cleanup {
### operate docker containers ### operate docker containers
function operateDocker { 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)"
# determine action to take
if [ "$1" = "stop" ]; then
echo -e "${op}[$(stamp)] Stopping ${2}-mailcow container...${normal}" \ echo -e "${op}[$(stamp)] Stopping ${2}-mailcow container...${normal}" \
>> "$logFile" >> "$logFile"
docker-compose stop --timeout ${dockerStopTimeout} ${2}-mailcow \ docker-compose stop --timeout ${dockerStopTimeout} ${2}-mailcow \
2>> "$logFile" 2>> "$logFile"
# verify container stopped (should return true) # verify container stopped (should return true)
dockerResultState=$(docker inspect -f '{{ .State.Running }}' \ dockerResultState="$(docker inspect -f '{{ .State.Running }}' $containerName)"
$containerName)
# verify clean stop (exit code 0) # verify clean stop (exit code 0)
dockerResultExit=$(docker inspect -f '{{ .State.ExitCode }}' \ dockerResultExit="$(docker inspect -f '{{ .State.ExitCode }}' $containerName)"
$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 }}' \
$containerName)
fi fi
} }