From 653d23a843cc981bc8847d815a0a46ab5498510b Mon Sep 17 00:00:00 2001 From: andryyy Date: Mon, 8 May 2017 15:35:24 +0200 Subject: [PATCH] Migrate some settings and DKIM keys to Redis when starting --- data/Dockerfiles/php-fpm/Dockerfile | 8 ++- data/Dockerfiles/php-fpm/docker-entrypoint.sh | 53 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/data/Dockerfiles/php-fpm/Dockerfile b/data/Dockerfiles/php-fpm/Dockerfile index 9a059a45..ad03b8ad 100644 --- a/data/Dockerfiles/php-fpm/Dockerfile +++ b/data/Dockerfiles/php-fpm/Dockerfile @@ -4,7 +4,13 @@ MAINTAINER Andre Peters ENV DEBIAN_FRONTEND noninteractive RUN apt-get update \ - && apt-get install -y zlib1g-dev libicu-dev g++ libidn11-dev libxml2-dev + && apt-get install -y zlib1g-dev \ + libicu-dev \ + g++ \ + libidn11-dev \ + libxml2-dev \ + redis-tools \ + mysql-client RUN docker-php-ext-configure intl RUN docker-php-ext-install intl pdo pdo_mysql xmlrpc diff --git a/data/Dockerfiles/php-fpm/docker-entrypoint.sh b/data/Dockerfiles/php-fpm/docker-entrypoint.sh index 8f57a6d9..1e4d3fe6 100755 --- a/data/Dockerfiles/php-fpm/docker-entrypoint.sh +++ b/data/Dockerfiles/php-fpm/docker-entrypoint.sh @@ -4,4 +4,57 @@ set -e if [[ ! -d "/data/dkim/txt" || ! -d "/data/dkim/keys" ]] ; then mkdir -p /data/dkim/{txt,keys} ; chown -R www-data:www-data /data/dkim; fi if [[ $(stat -c %U /data/dkim/) != "www-data" ]] ; then chown -R www-data:www-data /data/dkim ; fi +# Wait for containers + +while ! mysqladmin ping --host mysql --silent; do + sleep 2 +done + +until [ $(redis-cli -h redis-mailcow PING) == "PONG" ]; do + sleep 2 +done + +# Migrate domain map + +declare -a DOMAIN_ARR +redis-cli -h redis-mailcow DEL DOMAIN_MAP +while read line +do + DOMAIN_ARR+=("$line") +done < <(mysql -h mysql-mailcow -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "SELECT domain FROM domain" -Bs) + +if [[ ! -z ${DOMAIN_ARR} ]]; then +for domain in "${DOMAIN_ARR[@]}"; do + redis-cli -h redis-mailcow HSET DOMAIN_MAP ${domain} 1 +done +fi + +# Migrate tag settings map + +declare -a SUBJ_TAG_ARR +redis-cli -h redis-mailcow DEL SUBJ_TAG_ARR +while read line +do + SUBJ_TAG_ARR+=("$line") +done < <(mysql -h mysql-mailcow -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "SELECT username FROM mailbox WHERE wants_tagged_subject='1'" -Bs) + +if [[ ! -z ${SUBJ_TAG_ARR} ]]; then +for user in "${SUBJ_TAG_ARR[@]}"; do + redis-cli -h redis-mailcow HSET RCPT_WANTS_SUBJECT_TAG ${user} 1 + mysql -h mysql-mailcow -u ${DBUSER} -p${DBPASS} ${DBNAME} -e "UPDATE mailbox SET wants_tagged_subject='2' WHERE username = '${user}'" +done +fi + +# Migrate DKIM keys + +for file in $(ls /data/dkim/keys/); do + domain=${file%.dkim} + if [[ -f /data/dkim/txt/${file} ]]; then + redis-cli -h redis-mailcow HSET DKIM_PUB_KEYS "${domain}" "$(cat /data/dkim/keys/${domain})" + redis-cli -h redis-mailcow HSET DKIM_PRIV_KEYS "${domain}" "$(cat /data/dkim/keys/${file})" + redis-cli -h redis-mailcow HSET DKIM_SELECTORS "${domain}" "dkim.${domain}" + fi + rm /data/dkim/{keys,txt}/${file} +done + exec "$@"