Created
January 21, 2015 14:18
-
-
Save chrisnew/b0c1b8d310fc5ceaeac4 to your computer and use it in GitHub Desktop.
postfix-wrapper.sh for supervisord in docker. Controls postfix as it gets controlled by supervisord.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# postfix-wrapper.sh, version 0.1.0 | |
# | |
# You cannot start postfix in some foreground mode and | |
# it's more or less important that docker doesn't kill | |
# postfix and its chilren if you stop the container. | |
# | |
# Use this script with supervisord and it will take | |
# care about starting and stopping postfix correctly. | |
# | |
# supervisord config snippet for postfix-wrapper: | |
# | |
# [program:postfix] | |
# process_name = postfix | |
# command = /path/to/postfix-wrapper.sh | |
# startsecs = 0 | |
# autorestart = false | |
# | |
trap "postfix stop" SIGINT | |
trap "postfix stop" SIGTERM | |
trap "postfix reload" SIGHUP | |
# force new copy of hosts there (otherwise links could be outdated) | |
cp /etc/hosts /var/spool/postfix/etc/hosts | |
# start postfix | |
postfix start | |
# lets give postfix some time to start | |
sleep 3 | |
# wait until postfix is dead (triggered by trap) | |
while kill -0 "`cat /var/spool/postfix/pid/master.pid`"; do | |
sleep 5 | |
done |
Thanks! I just had to change the test when running on Docker using the alpine
postfix, since the PID file have spaces before the actual number.
# Check every 5 seconds if postfix is still alive
PID_FILE="/var/spool/postfix/pid/master.pid"
while true; do
sleep 5
# Stop this script if no PID file is available
if [ ! -f "$PID_FILE" ]; then
break;
else
# Or if the numeric PID in the file can't receive a signal
PID="$(cat $PID_FILE | sed 's/[^0-9]*//g')"
if ! kill -0 "$PID" 2>/dev/null; then
break;
fi
fi
done
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, it works with rsyslog.
This is the run script I call