Skip to content

Commit

Permalink
Fix for #174: Try to refactor healthcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
bokysan committed Jan 9, 2024
1 parent df9771b commit 83b9af5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
4 changes: 1 addition & 3 deletions helm/mail/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions scripts/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions scripts/opendkim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 83b9af5

Please sign in to comment.