Q:

Using supervisord to control the postfix MTA

I am trying to use supervisord to control postfix. The usual method is to specify a command which starts the daemon, I use postfix -c /etc/postfix start. The postfix man page says that to stop you replace start with stop in the above command.
I do not see a way of specifying another command to stop a daemon, just a signal. The master manpage says that the TERM signal will function as if postfix abort was used but is silent on shutting down gracefully via a signal.
Also, the start/stop method of the first paragraph is tricky as far as supervisord is concerned. The script performs a bunch of checks and then invokes master, qmgr and pickup with master as the process group leader. Thus, supervisord has a handle on a useless PID (one the script was running as) and cannot therefore use that PID to stop the daemon. What it should have a handle to is the master process.
How far I've got:
[program:master]
process_name    = master
priority        = 5
directory       = /etc/postfix
command         = /usr/sbin/postfix -c /etc/postfix start
startsecs       = 0
user            = root
stopsignal      = INT

This starts postfix but cannot stop it.

A:

My solution is to write a wrapper script named postfix.sh as follows:
# call "postfix stop" when exiting
trap "{ echo Stopping postfix; /usr/sbin/postfix stop; exit 0; }" EXIT

# start postfix
/usr/sbin/postfix -c /etc/postfix start
# avoid exiting
sleep infinity   

After that, modify supervisord.conf:
[program:postfix]
command=path/to/postfix.sh 

