From b889c70db82593612157ea9da371db6d88e62711 Mon Sep 17 00:00:00 2001 From: andryyy Date: Wed, 5 Feb 2020 10:58:52 +0100 Subject: [PATCH] [Rspamd] Set Redis slaveof if not master, adjust redis configs automatically --- data/Dockerfiles/rspamd/Dockerfile | 2 +- data/Dockerfiles/rspamd/docker-entrypoint.sh | 27 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/data/Dockerfiles/rspamd/Dockerfile b/data/Dockerfiles/rspamd/Dockerfile index 57f67e30..d4e98c2c 100644 --- a/data/Dockerfiles/rspamd/Dockerfile +++ b/data/Dockerfiles/rspamd/Dockerfile @@ -15,7 +15,7 @@ RUN apt-get update && apt-get install -y \ && apt-key adv --fetch-keys https://rspamd.com/apt-stable/gpg.key \ && echo "deb [arch=amd64] https://rspamd.com/apt-stable/ $CODENAME main" > /etc/apt/sources.list.d/rspamd.list \ && apt-get update \ - && apt-get --no-install-recommends -y install rspamd \ + && apt-get --no-install-recommends -y install rspamd redis-tools \ && rm -rf /var/lib/apt/lists/* \ && apt-get autoremove --purge \ && apt-get clean \ diff --git a/data/Dockerfiles/rspamd/docker-entrypoint.sh b/data/Dockerfiles/rspamd/docker-entrypoint.sh index 14d7a665..c0f0ee26 100755 --- a/data/Dockerfiles/rspamd/docker-entrypoint.sh +++ b/data/Dockerfiles/rspamd/docker-entrypoint.sh @@ -52,6 +52,33 @@ if [[ ! -z ${RSPAMD_V6} ]]; then echo ${RSPAMD_V6}/128 >> /etc/rspamd/custom/rspamd_trusted.map fi +if [[ ! -z ${REDIS_SLAVEOF_IP} ]]; then + cat < /etc/rspamd/local.d/redis.conf +read_servers = "redis:6379"; +write_servers = "${REDIS_SLAVEOF_IP}:${REDIS_SLAVEOF_PORT}"; +timeout = 10; +EOF + until [[ $(redis-cli -h redis-mailcow PING) == "PONG" ]]; do + echo "Waiting for Redis slave..." + sleep 2 + done + until [[ $(redis-cli -h ${REDIS_SLAVEOF_IP} -p ${REDIS_SLAVEOF_PORT} PING) == "PONG" ]]; do + echo "Waiting for Redis master..." + sleep 2 + done + redis-cli -h redis-mailcow SLAVEOF ${REDIS_SLAVEOF_IP} ${REDIS_SLAVEOF_PORT} +else + cat < /etc/rspamd/local.d/redis.conf +servers = "redis:6379"; +timeout = 10; +EOF + until [[ $(redis-cli -h redis-mailcow PING) == "PONG" ]]; do + echo "Waiting for Redis slave..." + sleep 2 + done + redis-cli -h redis-mailcow SLAVEOF NO ONE +fi + chown -R _rspamd:_rspamd /var/lib/rspamd \ /etc/rspamd/local.d \ /etc/rspamd/override.d \