From 15fb2e22eaecd30cc5ae6345803d3894a778ad2e Mon Sep 17 00:00:00 2001 From: andryyy Date: Wed, 5 Feb 2020 10:58:04 +0100 Subject: [PATCH] [Postfix] Use Redis master if set --- data/Dockerfiles/postfix/Dockerfile | 7 ++- data/Dockerfiles/postfix/docker-entrypoint.sh | 7 +++ .../postfix/syslog-ng-redis_slave.conf | 49 +++++++++++++++++++ 3 files changed, 61 insertions(+), 2 deletions(-) create mode 100755 data/Dockerfiles/postfix/docker-entrypoint.sh create mode 100644 data/Dockerfiles/postfix/syslog-ng-redis_slave.conf diff --git a/data/Dockerfiles/postfix/Dockerfile b/data/Dockerfiles/postfix/Dockerfile index d5cf167a..5e7afd2f 100644 --- a/data/Dockerfiles/postfix/Dockerfile +++ b/data/Dockerfiles/postfix/Dockerfile @@ -39,21 +39,24 @@ RUN groupadd -g 102 postfix \ COPY supervisord.conf /etc/supervisor/supervisord.conf COPY syslog-ng.conf /etc/syslog-ng/syslog-ng.conf +COPY syslog-ng-redis_slave.conf /etc/syslog-ng/syslog-ng-redis_slave.conf COPY stop-supervisor.sh /usr/local/sbin/stop-supervisor.sh COPY postfix.sh /opt/postfix.sh COPY rspamd-pipe-ham /usr/local/bin/rspamd-pipe-ham COPY rspamd-pipe-spam /usr/local/bin/rspamd-pipe-spam COPY whitelist_forwardinghosts.sh /usr/local/bin/whitelist_forwardinghosts.sh COPY stop-supervisor.sh /usr/local/sbin/stop-supervisor.sh +COPY docker-entrypoint.sh /docker-entrypoint.sh RUN chmod +x /opt/postfix.sh \ /usr/local/bin/rspamd-pipe-ham \ /usr/local/bin/rspamd-pipe-spam \ /usr/local/bin/whitelist_forwardinghosts.sh \ /usr/local/sbin/stop-supervisor.sh +RUN rm -rf /tmp/* /var/tmp/* EXPOSE 588 -CMD exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf +ENTRYPOINT ["/docker-entrypoint.sh"] -RUN rm -rf /tmp/* /var/tmp/* +CMD exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf diff --git a/data/Dockerfiles/postfix/docker-entrypoint.sh b/data/Dockerfiles/postfix/docker-entrypoint.sh new file mode 100755 index 00000000..ffa64d2c --- /dev/null +++ b/data/Dockerfiles/postfix/docker-entrypoint.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +if [[ ! -z ${REDIS_SLAVEOF_IP} ]]; then + cp /etc/syslog-ng/syslog-ng-redis_slave.conf /etc/syslog-ng/syslog-ng.conf +fi + +exec "$@" diff --git a/data/Dockerfiles/postfix/syslog-ng-redis_slave.conf b/data/Dockerfiles/postfix/syslog-ng-redis_slave.conf new file mode 100644 index 00000000..b3c0adda --- /dev/null +++ b/data/Dockerfiles/postfix/syslog-ng-redis_slave.conf @@ -0,0 +1,49 @@ +@version: 3.19 +@include "scl.conf" +options { + chain_hostnames(off); + flush_lines(0); + use_dns(no); + dns_cache(no); + use_fqdn(no); + owner("root"); group("adm"); perm(0640); + stats_freq(0); + bad_hostname("^gconfd$"); +}; +source s_src { + unix-stream("/dev/log"); + internal(); +}; +destination d_stdout { pipe("/dev/stdout"); }; +destination d_redis_ui_log { + redis( + host("`REDIS_SLAVEOF_IP`") + persist-name("redis1") + port(`REDIS_SLAVEOF_PORT`) + command("LPUSH" "POSTFIX_MAILLOG" "$(format-json time=\"$S_UNIXTIME\" priority=\"$PRIORITY\" program=\"$PROGRAM\" message=\"$MESSAGE\")\n") + ); +}; +destination d_redis_f2b_channel { + redis( + host("`REDIS_SLAVEOF_IP`") + persist-name("redis2") + port(`REDIS_SLAVEOF_PORT`) + command("PUBLISH" "F2B_CHANNEL" "$MESSAGE") + ); +}; +filter f_mail { facility(mail); }; +# start +# overriding warnings are still displayed when the entrypoint runs its initial check +# warnings logged by postfix-mailcow to syslog are hidden to reduce repeating msgs +filter f_overrides { not match("overriding earlier entry" value("MESSAGE")); }; +# end +filter f_skip_local { not facility (local0, local1, local2, local3, local4, local5, local6, local7); }; +log { + source(s_src); + filter(f_skip_local); + filter(f_overrides); + destination(d_stdout); + filter(f_mail); + destination(d_redis_ui_log); + destination(d_redis_f2b_channel); +};