NobGit
public nobgit read

NobMail

Based on mailcow: dockerized

Languages

Repository composition by tracked source files.

PHP
PHP 49% JavaScript 35% HTML 9% CSS 4% Shell 2% Python 1% Lua 0% Perl 0% Ruby 0% SCSS 0%
Create file Wiki Documentation
Clone
https://nobgit.com/orgs/nobgit/nobmail.git
ssh://[email protected]:2222/orgs/nobgit/nobmail.git

Commit

[PHP-FPM] Check if master, write to Redis master only

f6b3a6e8
andryyy <[email protected]> 6 years ago
data/Dockerfiles/phpfpm/docker-entrypoint.sh | 33 +++++++++++++++++-----------
 1 file changed, 20 insertions(+), 13 deletions(-)

Diff

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