Nondaemonizing of Subprocesses

Programs meant to be run under supervisor should not daemonizethemselves. Instead, they should run in the foreground. They shouldnot detach from the terminal from which they are started.

The easiest way to tell if a program will run in the foreground is torun the command that invokes the program from a shell prompt. If itgives you control of the terminal back, but continues running, it’sdaemonizing itself and that will almost certainly be the wrong way torun it under supervisor. You want to run a command that essentiallyrequires you to press Ctrl-C to get control of the terminalback. If it gives you a shell prompt back after running it withoutneeding to press Ctrl-C, it’s not useful under supervisor. Allprograms have options to be run in the foreground but there’s no“standard way” to do it; you’ll need to read the documentation foreach program.

Below are configuration file examples that are known to startcommon programs in “foreground” mode under Supervisor.

Examples of Program Configurations

Here are some “real world” program configuration examples:

Apache 2.2.6

  1. [program:apache2]
  2. command=/path/to/httpd -c "ErrorLog /dev/stdout" -DFOREGROUND
  3. redirect_stderr=true

Two Zope 2.X instances and one ZEO server

  1. [program:zeo]
  2. command=/path/to/runzeo
  3. priority=1
  4.  
  5. [program:zope1]
  6. command=/path/to/instance/home/bin/runzope
  7. priority=2
  8. redirect_stderr=true
  9.  
  10. [program:zope2]
  11. command=/path/to/another/instance/home/bin/runzope
  12. priority=2
  13. redirect_stderr=true

Postgres 8.X

  1. [program:postgres]
  2. command=/path/to/postmaster
  3. ; we use the "fast" shutdown signal SIGINT
  4. stopsignal=INT
  5. redirect_stderr=true

OpenLDAP slapd

  1. [program:slapd]
  2. command=/path/to/slapd -f /path/to/slapd.conf -h ldap://0.0.0.0:8888
  3. redirect_stderr=true

Other Examples

Other examples of shell scripts that could be used to start servicesunder supervisord can be found athttp://thedjbway.b0llix.net/services.html. These examples areactually for daemontools but the premise is the same forsupervisor.

Another collection of recipes for starting various programs in theforeground is available from http://smarden.org/runit/runscripts.html.