[ZODB-Dev] Daemon manager design issues

Guido van Rossum guido@python.org
Fri, 08 Nov 2002 17:59:57 -0500


I'm writing a simple "daemon manager", a program to replace zdaemon.
You can review my attempts in Zope or ZODB3 CVS as zdaemon/zdaemon.py
(not necessarily its final resting place).

My terminology: I call the parent process, which takes care of
restarting, the (daemon) manager.  I call the child process, which
runs the actual daemon (= server) code, the (daemon) application.

I've got some design questions where I'd like to hear from potential
users (especially since this will be used to run Zope too, and I don't
know much about running Zope myself).

- There needs to be a way to stop the daemon manager (and the daemon
  application).  Shall I do this with a signal or with a separate
  utility that talkes to the daemon manager, perhaps through a
  Unix-domain socket?

- Ditto for restarting the daemon application.  I guess this has to
  kill the application with a signal, unless we want to get fancy and
  decide on a separate parent-child protocol (which I think would be
  overkill).  We could do this in three ways:

  - Use a separate utility as described above.

  - Send the signal directly to the application (this means there has
    to be a file with the application's pid; the daemon can write
    this);

  - Send the signal to the manager, which passes it on.

- Logging is configured through environment variables, which are
  passed on to the application.  Is there a need to be able to
  configure the manager's logging separately from the application, or
  is it okay that the manager always logs to the same file as the
  application?

- Are there any other features missing from the daemon manager?

Here's the docstring:

"""
zdaemon -- run an application as a daemon.

Usage: python zdaemon.py [zdaemon-options] program [program-arguments]

Options:
  -b SECONDS -- set backoff limit to SECONDS (default 10; see below)
  -d -- run as a proper daemon; fork a background process, close files etc.
  -f -- run forever (by default, exit when the backoff limit is exceeded)
  -h -- print usage message and exit
  program [program-arguments] -- an arbitrary application to run

This daemon manager has two purposes: it restarts the application when
it dies, and (when requested to do so with the -d option) it runs the
application in the background, detached from the foreground tty
session that started it (if any).

Important: if at any point the application exits with exit status 2,
it is not restarted.  Any other form of termination (either being
killed by a signal or exiting with an exit status other than 2) causes
it to be restarted.

Backoff limit: when the application exits (nearly) immediately after a
restart, the daemon manager starts slowing down by delaying between
restarts.  The delay starts at 1 second and is increased by one on
each restart up to the backoff limit given by the -b option; it is
reset when the application runs for more than the backoff limit
seconds.  By default, when the delay reaches the backoff limit, the
daemon manager exits (under the assumption that the application has a
persistent fault).  The -f (forever) option prevents this exit; use it
when you expect that a temporary external problem (such as a network
outage or an overfull disk) may prevent the application from starting
but you want the daemon manager to keep trying.
"""

--Guido van Rossum (home page: http://www.python.org/~guido/)