[Zope-dev] [PATCH] Forking daemon in debug mode, and new start scripts

Adrian van den Dries adriand@flow.com.au
Mon, 20 Jan 2003 16:57:55 +1100


--W/nzBZO5zC0uMSeA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

I understand zdaemon is going away soon, but here's a small patch to
Daemon.py to fork if it finds an EVENT_LOG_FILE.

Also included is my start/stop scripts (for Unix), and a
custom_zodb.py which uses an environment variable ZODB_STORAGE to
determine what storage to use.  This allows me to use the same
codebase for my ZEO client Zopes and local FileStorage Zopes, simply
by changing a /etc/defaults style config file, also included.

The scripts in their current form may not be entirely suitable, but
they provide a point of departure for a slightly better startup
mechanism.

The non-detaching daemon, however, is just plain annoying.  On Unix
you can always tail the logfile for the same effect.

a.

-- 
 Adrian van den Dries                           adriand@flow.com.au
 Development team                               www.dev.flow.com.au
 FLOW Communications Pty. Ltd.                  www.flow.com.au

--W/nzBZO5zC0uMSeA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="Daemon.py.diff"

--- Daemon.py.orig	2002-08-15 08:12:52.000000000 +1000
+++ Daemon.py	2003-01-20 15:59:45.000000000 +1100
@@ -29,7 +29,8 @@
 
     os.environ['ZDAEMON_MANAGED']='TRUE'
 
-    if not os.environ.has_key('Z_DEBUG_MODE'):
+    if not (os.environ.has_key('Z_DEBUG_MODE') and
+            not os.environ.has_key('EVENT_LOG_FILE')):
         detach() # detach from the controlling terminal
 
     while 1:

--W/nzBZO5zC0uMSeA
Content-Type: application/x-sh
Content-Disposition: attachment; filename="config.sh"
Content-Transfer-Encoding: quoted-printable

#!/bin/sh=0A=0AZOPE_HOME=3D/path/to/Zope=0A=0A# this is either a full path =
or python expression to get eval'd=0AZODB_STORAGE=3D$ZOPE_HOME/var/Data.fs=
=0A#ZODB_STORAGE=3D"('zeo-server', 1975)"=0A=0AHTTP_PORT=3D9880=0AFTP_PORT=
=3D9821=0AWEBDAV_PORT=3D9881=0AMONITOR_PORT=3D9882=0A=0A#EVENT_LOG_FILE=3De=
vent.log=0A#EVENT_LOG_SEVERITY=3D-100=0A=0A#Z_DEBUG_MODE=3Dyes=0A
--W/nzBZO5zC0uMSeA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=start

#!/bin/sh

. $(dirname $0)/config.sh

export ZOPE_HOME SOFTWARE_HOME INSTANCE_HOME CLIENT_HOME ZODB_STORAGE
export EVENT_LOG_FILE EVENT_LOG_SEVERITY Z_DEBUG_MODE

cd $ZOPE_HOME

umask 077

if [ "$MONITOR_PORT" ]; then
    MONITOR="-m $MONITOR_PORT"
fi

if [ "$WEBDAV_PORT" ]; then
    WEBDAV="-W $WEBDAV_PORT"
fi

if [ "$HTTP_PORT" ]; then
    HTTP="-w $HTTP_PORT"
fi

if [ "$FTP_PORT" ]; then
    FTP="-f $FTP_PORT"
fi

exec python2.1 $ZOPE_HOME/z2.py -X $HTTP $FTP $WEBDAV $MONITOR "$@"

--W/nzBZO5zC0uMSeA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=stop

#! /bin/sh

. $(dirname $0)/config.sh

kill $(cat $ZOPE_HOME/var/Z2.pid)

--W/nzBZO5zC0uMSeA
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="custom_zodb.py"

import os

ZODB_STORAGE = os.environ.get('ZODB_STORAGE', '')
if not ZODB_STORAGE:
    raise "NoStorageInEnvironmentError"

try:
    stg = eval(ZODB_STORAGE)
except:
    stg = ZODB_STORAGE

if type(stg) is type(''):
    from ZODB.FileStorage import FileStorage
    Storage = FileStorage(stg)
else:
    from ZEO.ClientStorage import ClientStorage
    Storage = ClientStorage(stg, name='ZEO server on %s' % stg[0])


--W/nzBZO5zC0uMSeA--