[Zodb-checkins] CVS: ZODB3/zdaemon - zdrun.py:1.1 zdaemon.py:NONE

Guido van Rossum guido@python.org
Sat, 18 Jan 2003 21:25:19 -0500


Update of /cvs-repository/ZODB3/zdaemon
In directory cvs.zope.org:/tmp/cvs-serv23681/zdaemon

Added Files:
	zdrun.py 
Removed Files:
	zdaemon.py 
Log Message:
Renamed zdaemon.py to zdrun.py, to avoid problems when runzeo.py and
zdaemon.py were both installed in /usr/local/bin/.


=== Added File ZODB3/zdaemon/zdrun.py === (716/816 lines abridged)
#! /usr/bin/env python
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""zdaemon -- run an application as a daemon.

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

Options:
  -b SECONDS -- set backoff limit to SECONDS (default 10; see below)
  -c -- client mode, to sends a command to the daemon manager; 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
  -s SOCKET -- Unix socket name for client communication (default "zdsock")
  -u USER -- run as this user (or numeric uid)
  -x LIST -- list of fatal exit codes (default "0,2"; use "" to disable)
  -z DIRECTORY -- directory to chdir into when using -d; default "/"
  program [program-arguments] -- an arbitrary application to run

Client mode options:
  -s SOCKET -- socket name (a Unix pathname) for client communication
  [command] -- the command to send to the daemon manager (default "status")

Client commands are:
  help -- return command help
  status -- report application status (this is the default command)
  kill [signal] -- send a signal to the application
                   (default signal is SIGTERM)
  start -- start the application if not already running
  stop -- stop the application if running; daemon manager keeps running
  restart -- stop followed by start
  exit -- stop the application and exit

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).


[-=- -=- -=- 716 lines omitted -=- -=- -=-]

        if iscore:
            msg += " (core dumped)"
        return -1, msg
    else:
        msg = "unknown termination cause 0x%04x" % sts
        return -1, msg

_signames = None

def signame(sig):
    """Return a symbolic name for a signal.

    Return "signal NNN" if there is no corresponding SIG name in the
    signal module.
    """

    if _signames is None:
        _init_signames()
    return _signames.get(sig) or "signal %d" % sig

def _init_signames():
    global _signames
    d = {}
    for k, v in signal.__dict__.items():
        k_startswith = getattr(k, "startswith", None)
        if k_startswith is None:
            continue
        if k_startswith("SIG") and not k_startswith("SIG_"):
            d[v] = k
    _signames = d

def get_path():
    """Return a list corresponding to $PATH, or a default."""
    path = ["/bin", "/usr/bin", "/usr/local/bin"]
    if os.environ.has_key("PATH"):
        p = os.environ["PATH"]
        if p:
            path = p.split(os.pathsep)
    return path

# Main program

def main(args=None):
    assert os.name == "posix", "This code makes many Unix-specific assumptions"
    zLOG.initialize()
    d = Daemonizer()
    d.main(args)

if __name__ == "__main__":
    main()

=== Removed File ZODB3/zdaemon/zdaemon.py ===