From 4a403e93232859a7c6265fd454dd68a4484967c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9?= Date: Sun, 3 Jun 2018 19:22:44 +0200 Subject: [PATCH] [Dovecot] Imapsync: Set is_running = 0 on restart --- data/Dockerfiles/dovecot/Dockerfile | 1 + data/Dockerfiles/dovecot/docker-entrypoint.sh | 10 ++++++++++ docker-compose.yml | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/data/Dockerfiles/dovecot/Dockerfile b/data/Dockerfiles/dovecot/Dockerfile index 47bfc20aa..f8f4e013a 100644 --- a/data/Dockerfiles/dovecot/Dockerfile +++ b/data/Dockerfiles/dovecot/Dockerfile @@ -56,6 +56,7 @@ RUN apt-get update && apt-get -y --no-install-recommends install \ liburi-perl \ lzma-dev \ make \ + mysql-client \ procps \ supervisor \ cron \ diff --git a/data/Dockerfiles/dovecot/docker-entrypoint.sh b/data/Dockerfiles/dovecot/docker-entrypoint.sh index 3ee3f5095..be095355b 100755 --- a/data/Dockerfiles/dovecot/docker-entrypoint.sh +++ b/data/Dockerfiles/dovecot/docker-entrypoint.sh @@ -1,6 +1,12 @@ #!/bin/bash set -e +# Wait for MySQL to warm-up +while ! mysqladmin ping --host mysql -u${DBUSER} -p${DBPASS} --silent; do + echo "Waiting for database to come up..." + sleep 2 +done + # Hard-code env vars to imapsync due to cron not passing them to the perl script sed -i "/^\$DBUSER/c\\\$DBUSER='${DBUSER}';" /usr/local/bin/imapsync_cron.pl sed -i "/^\$DBPASS/c\\\$DBPASS='${DBPASS}';" /usr/local/bin/imapsync_cron.pl @@ -123,4 +129,8 @@ touch /etc/crontab /etc/cron.*/* # Clean old PID if any [[ -f /usr/local/var/run/dovecot/master.pid ]] && rm /usr/local/var/run/dovecot/master.pid +# Clean stopped imapsync jobs +IMAPSYNC_TABLE=$(mysql -h mysql-mailcow -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "SHOW TABLES LIKE 'imapsync'" -Bs) +[[ ! -z ${IMAPSYNC_TABLE} ]] && mysql -h mysql-mailcow -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "UPDATE imapsync SET is_running='0'" + exec "$@" diff --git a/docker-compose.yml b/docker-compose.yml index b1abc560c..546be3a0a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -167,7 +167,7 @@ services: - sogo dovecot-mailcow: - image: mailcow/dovecot:1.26 + image: mailcow/dovecot:1.27 build: ./data/Dockerfiles/dovecot cap_add: - NET_BIND_SERVICE