From f6b3a6e87454b1fe812513a4c76181d071f15ff4 Mon Sep 17 00:00:00 2001 From: andryyy Date: Wed, 5 Feb 2020 10:57:37 +0100 Subject: [PATCH] [PHP-FPM] Check if master, write to Redis master only --- data/Dockerfiles/phpfpm/docker-entrypoint.sh | 33 ++++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/data/Dockerfiles/phpfpm/docker-entrypoint.sh b/data/Dockerfiles/phpfpm/docker-entrypoint.sh index f4148a12..74b61034 100755 --- a/data/Dockerfiles/phpfpm/docker-entrypoint.sh +++ b/data/Dockerfiles/phpfpm/docker-entrypoint.sh @@ -8,21 +8,28 @@ while ! mysqladmin status --socket=/var/run/mysqld/mysqld.sock -u${DBUSER} -p${D sleep 2 done -until [[ $(redis-cli -h redis-mailcow PING) == "PONG" ]]; do +# Do not attempt to write to slave +if [[ ! -z ${REDIS_SLAVEOF_IP} ]]; then + REDIS_CMDLINE="redis-cli -h ${REDIS_SLAVEOF_IP} -p ${REDIS_SLAVEOF_PORT}" +else + REDIS_CMDLINE="redis-cli -h redis -p 6379" +fi + +until [[ $(${REDIS_CMDLINE} PING) == "PONG" ]]; do echo "Waiting for Redis..." sleep 2 done +if [[ "${MASTER}" =~ ^([yY][eE][sS]|[yY])+$ ]]; then + echo "We are master, preparing..." # Set a default release format - -if [[ -z $(redis-cli --raw -h redis-mailcow GET Q_RELEASE_FORMAT) ]]; then - redis-cli --raw -h redis-mailcow SET Q_RELEASE_FORMAT raw +if [[ -z $(${REDIS_CMDLINE} --raw GET Q_RELEASE_FORMAT) ]]; then + ${REDIS_CMDLINE} --raw SET Q_RELEASE_FORMAT raw fi # Set max age of q items - if unset - -if [[ -z $(redis-cli --raw -h redis-mailcow GET Q_MAX_AGE) ]]; then - redis-cli --raw -h redis-mailcow SET Q_MAX_AGE 365 +if [[ -z $(${REDIS_CMDLINE} --raw GET Q_MAX_AGE) ]]; then + ${REDIS_CMDLINE} --raw SET Q_MAX_AGE 365 fi # Check mysql_upgrade @@ -90,7 +97,7 @@ php -c /usr/local/etc/php -f /web/inc/init_db.inc.php # Recreating domain map echo "Rebuilding domain map in Redis..." declare -a DOMAIN_ARR - redis-cli -h redis-mailcow DEL DOMAIN_MAP > /dev/null + ${REDIS_CMDLINE} DEL DOMAIN_MAP > /dev/null while read line do DOMAIN_ARR+=("$line") @@ -102,15 +109,11 @@ done < <(mysql --socket=/var/run/mysqld/mysqld.sock -u ${DBUSER} -p${DBPASS} ${D if [[ ! -z ${DOMAIN_ARR} ]]; then for domain in "${DOMAIN_ARR[@]}"; do - redis-cli -h redis-mailcow HSET DOMAIN_MAP ${domain} 1 > /dev/null + ${REDIS_CMDLINE} HSET DOMAIN_MAP ${domain} 1 > /dev/null done fi -# Create dummy for custom overrides of mailcow style -[[ ! -f /web/css/build/0081-custom-mailcow.css ]] && echo '/* Autogenerated by mailcow */' > /web/css/build/0081-custom-mailcow.css - # Set API options if env vars are not empty - if [[ ${API_ALLOW_FROM} != "invalid" ]] && \ [[ ${API_KEY} != "invalid" ]] && \ [[ ! -z ${API_KEY} ]] && \ @@ -157,6 +160,10 @@ END; // DELIMITER ; EOF +fi + +# Create dummy for custom overrides of mailcow style +[[ ! -f /web/css/build/0081-custom-mailcow.css ]] && echo '/* Autogenerated by mailcow */' > /web/css/build/0081-custom-mailcow.css # Run hooks for file in /hooks/*; do