Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question

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 
share|improve this answer

Turns out that it is simpler to use something like Monit to monitor daemons:

Monit is a free open source utility for managing and monitoring, processes, programs, files, directories and filesystems on a UNIX system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations.

You can use Monit to monitor daemon processes or similar programs running on localhost. Monit is particular useful for monitoring daemon processes, such as those started at system boot time from /etc/init.d/. For instance sendmail, sshd, apache and mysql.

enter image description here

share|improve this answer

The same as @Hui Zheng but checking if posfix is alive

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

credits goes here

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .