diff --git a/Dockerfile b/Dockerfile index ae4c04f..5f10478 100644 --- a/Dockerfile +++ b/Dockerfile @@ -61,7 +61,7 @@ VOLUME [ "/var/spool/postfix", "/etc/postfix", "/etc/opendkim/keys" ] USER root WORKDIR /tmp -HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --start-interval=2s --retries=3 CMD printf "EHLO healthcheck\nquit\n" | { while read l ; do sleep 1; echo $l; done } | nc -w 2 127.0.0.1 587 | grep -qE "^220.*ESMTP Postfix" +HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --start-interval=2s --retries=3 CMD /scripts/healthcheck.sh EXPOSE 587 CMD [ "/bin/sh", "-c", "/scripts/run.sh" ] diff --git a/helm/mail/values.yaml b/helm/mail/values.yaml index 32b9ba9..82bca42 100644 --- a/helm/mail/values.yaml +++ b/helm/mail/values.yaml @@ -209,9 +209,7 @@ readinessProbe: command: - sh - -c - - >- - [ ! -f /tmp/container_is_terminating ] && - printf "EHLO healthcheck\nquit\n" | { while read l ; do sleep 1; echo $l; done } | nc -w 2 127.0.0.1 587 | grep -qE "^220.*ESMTP Postfix" + - /scripts/healthcheck.sh livenessProbe: initialDelaySeconds: 5 periodSeconds: 5 diff --git a/scripts/healthcheck.sh b/scripts/healthcheck.sh new file mode 100644 index 0000000..abc95ae --- /dev/null +++ b/scripts/healthcheck.sh @@ -0,0 +1,22 @@ +#!/bin/sh +set -e +if [ -f /tmp/container_is_terminating ]; then + exit 0 +fi + +check_postfix() { + printf "EHLO healthcheck\nquit\n" | \ + { while read l ; do sleep 1; echo $l; done } | \ + nc -w 2 127.0.0.1 587 | \ + grep -qE "^220.*ESMTP Postfix" +} + +check_dkim() { + if [ -f /tmp/no_open_dkim ]; then + return + fi + printf '\x18Clocalhost\x004\x00\x00127.0.0.1\x00' | nc -w 2 127.0.0.1 8891 +} + +check_postfix +check_dkim diff --git a/scripts/opendkim.sh b/scripts/opendkim.sh index 1f27bfd..385b4e0 100755 --- a/scripts/opendkim.sh +++ b/scripts/opendkim.sh @@ -9,8 +9,10 @@ noop() { } if [ ! -d /etc/opendkim/keys ]; then + touch /tmp/no_open_dkim noop elif [ -z "$(find /etc/opendkim/keys -type f ! -name .)" ]; then + touch /tmp/no_open_dkim noop else exec /usr/sbin/opendkim -D -f -x /etc/opendkim/opendkim.conf