Compare commits

..

7 Commits

View File

@ -197,7 +197,7 @@ function cleanup {
## restart mailflow docker containers ## restart mailflow docker containers
# start and verify postfix # start and verify postfix
operateDocker start postfix operateDocker start postfix
if [ "$dockerResult" = "true" ]; then if [ "$dockerResultState" = "true" ]; then
echo -e "${info}${stamp} -- [INFO] Postfix container is running --" \ echo -e "${info}${stamp} -- [INFO] Postfix container is running --" \
"${normal}" >> "$logFile" "${normal}" >> "$logFile"
else else
@ -205,7 +205,7 @@ function cleanup {
fi fi
# start and verify dovecot # start and verify dovecot
operateDocker start dovecot operateDocker start dovecot
if [ "$dockerResult" = "true" ]; then if [ "$dockerResultState" = "true" ]; then
echo -e "${info}${stamp} -- [INFO] Dovecot container is running --" \ echo -e "${info}${stamp} -- [INFO] Dovecot container is running --" \
"${normal}" >> "$logFile" "${normal}" >> "$logFile"
else else
@ -221,14 +221,19 @@ if [ "$1" = "stop" ]; then
>> "$logFile" >> "$logFile"
docker-compose stop --timeout ${dockerStopTimeout} ${2}-mailcow \ docker-compose stop --timeout ${dockerStopTimeout} ${2}-mailcow \
2>> "$logFile" 2>> "$logFile"
# verify # verify container stopped (should return true)
dockerResult=$(docker inspect -f '{{ .State.ExitCode }}' ${COMPOSE_PROJECT_NAME}_${2}-mailcow_1) dockerResultState=$(docker inspect -f '{{ .State.Running }}' \
${COMPOSE_PROJECT_NAME}_${2}-mailcow_1)
# verify clean stop (exit code 0)
dockerResultExit=$(docker inspect -f '{{ .State.ExitCode }}' \
${COMPOSE_PROJECT_NAME}_${2}-mailcow_1)
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
dockerResult=$(docker inspect -f '{{ .State.Running }}' ${COMPOSE_PROJECT_NAME}_${2}-mailcow_1) dockerResultState=$(docker inspect -f '{{ .State.Running }}' \
${COMPOSE_PROJECT_NAME}_${2}-mailcow_1)
fi fi
} }
@ -438,6 +443,9 @@ echo -e "${info}${stamp} -- [INFO] using ${lit}${dockerComposeFilePath}" \
### Import additional variables from mailcow configuration file ### Import additional variables from mailcow configuration file
source "${mailcowConfigFilePath}" source "${mailcowConfigFilePath}"
### Export PATH so this script can access all docker and docker-compose commands
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
### Export logFile variable for use by Borg ### Export logFile variable for use by Borg
export logFile="$logFile" export logFile="$logFile"
@ -524,7 +532,7 @@ cd "$mailcowPath"
## Stop postfix-mailcow container ## Stop postfix-mailcow container
operateDocker stop postfix operateDocker stop postfix
# process result # process result
if [ "$dockerResult" -eq 0 ]; then if [ "$dockerResultState" = "false" ] && [ "$dockerResultExit" -eq 0 ]; then
echo -e "${info}${stamp} -- [INFO] Postfix container stopped --${normal}" \ echo -e "${info}${stamp} -- [INFO] Postfix container stopped --${normal}" \
>> "$logFile" >> "$logFile"
else else
@ -535,7 +543,7 @@ fi
## Stop dovecot-mailcow container ## Stop dovecot-mailcow container
operateDocker stop dovecot operateDocker stop dovecot
# process result # process result
if [ "$dockerResult" -eq 0 ]; then if [ "$dockerResultState" = "false" ] && [ "$dockerResultExit" -eq 0 ]; then
echo -e "${info}${stamp} -- [INFO] Dovecot container stopped --${normal}" \ echo -e "${info}${stamp} -- [INFO] Dovecot container stopped --${normal}" \
>> "$logFile" >> "$logFile"
else else
@ -548,7 +556,7 @@ fi
### Dump SQL ### Dump SQL
echo -e "${op}${stamp} Dumping mailcow SQL database...${normal}" >> "$logFile" echo -e "${op}${stamp} Dumping mailcow SQL database...${normal}" >> "$logFile"
docker-compose exec mysql-mailcow mysqldump --default-character-set=utf8mb4 -u${DBUSER} -p${DBPASS} ${DBNAME} > "$sqlDumpDir/$sqlDumpFile" 2>> "$logFile" docker-compose exec mysql-mailcow mysqldump --default-character-set=utf8mb4 -u${DBUSER} -p${DBPASS} ${DBNAME} > "$sqlDumpDir/$sqlDumpFile" 2>> "$logFile"
checkResult=$(docker-compose exec mysql-mailcow echo "$?") checkResult=$(docker-compose exec -T mysql-mailcow echo $?)
# verify sql dump was successful # verify sql dump was successful
if [ "$checkResult" = 0 ]; then if [ "$checkResult" = 0 ]; then
echo -e "${ok}${stamp} -- [SUCCESS] SQL successfully dumped --${normal}" \ echo -e "${ok}${stamp} -- [SUCCESS] SQL successfully dumped --${normal}" \
@ -561,7 +569,7 @@ fi
### Save redis state ### Save redis state
echo -e "${op}${stamp} Saving redis state information...${normal}" >> "$logFile" echo -e "${op}${stamp} Saving redis state information...${normal}" >> "$logFile"
docker-compose exec redis-mailcow redis-cli save >> "$logFile" 2>&1 docker-compose exec redis-mailcow redis-cli save >> "$logFile" 2>&1
checkResult=$(docker-compose exec redis-mailcow echo "$?") checkResult=$(docker-compose exec -T redis-mailcow echo "$?")
# Verify save was successful # Verify save was successful
if [ "$checkResult" = 0 ]; then if [ "$checkResult" = 0 ]; then
echo -e "${ok}${stamp} -- [SUCCESS] redis state saved --${normal}" \ echo -e "${ok}${stamp} -- [SUCCESS] redis state saved --${normal}" \