[Zope-Checkins] CVS: Zope/lib/python/Zope/Startup - __init__.py:1.8
Chris McDonough
chrism@zope.com
Sat, 19 Jul 2003 16:19:02 -0400
Update of /cvs-repository/Zope/lib/python/Zope/Startup
In directory cvs.zope.org:/tmp/cvs-serv3438
Modified Files:
__init__.py
Log Message:
Write a pidfile.
Ensure that ZServer startup messages make it to the logfile and to stdout if we're running in debug mode.
Fix some stale comments.
=== Zope/lib/python/Zope/Startup/__init__.py 1.7 => 1.8 ===
--- Zope/lib/python/Zope/Startup/__init__.py:1.7 Wed Jun 18 03:57:11 2003
+++ Zope/lib/python/Zope/Startup/__init__.py Sat Jul 19 16:18:58 2003
@@ -50,6 +50,7 @@
# set up our initial logging environment (log everything to stderr
# if we're not in debug mode).
import zLOG
+ import logging
# don't initialize the event logger from the environment
zLOG._call_initialize = 0
@@ -76,6 +77,9 @@
# set up our event logger temporarily with a startup handler
event_logger = zLOG.EventLogger.EventLogger.logger
event_logger.addHandler(startup_handler)
+ # set the initial logging level to INFO (this will be changed by the
+ # zconfig settings later)
+ event_logger.level = logging.INFO
# set a locale if one has been specified in the config
if cfg.locale:
@@ -104,7 +108,7 @@
% (server.servertype(),e[1]))
cfg.servers = servers
- # do stuff that only applies to posix platforms (setuid, daemonizing)
+ # do stuff that only applies to posix platforms (setuid mainly)
if os.name == 'posix':
do_posix_stuff(cfg)
@@ -112,9 +116,18 @@
import Zope
Zope.startup()
+ # this is a bit of a white lie, since we haven't actually successfully
+ # started yet, but we're pretty close and we want this output to
+ # go to the startup logger in order to prevent the kinds of email messages
+ # to the Zope maillist in which people claim that Zope has "frozen"
+ # after it has emitted ZServer messages ;-)
+ zLOG.LOG('Zope', zLOG.INFO, 'Ready to handle requests')
+
if not cfg.zserver_read_only_mode:
- # lock_file is used for the benefit of zctl, so it can tell whether
- # Zope is already running before attempting to fire it off again.
+ # lock_file is used for the benefit of zctl-like systems, so they
+ # can tell whether Zope is already running before attempting to fire
+ # it off again.
+ #
# We aren't concerned about locking the file to protect against
# other Zope instances running from our CLIENT_HOME, we just
# try to lock the file to signal that zctl should not try to
@@ -132,6 +145,17 @@
except IOError:
pass
+ # write the pid into the pidfile if possible
+ pid_filename = cfg.pid_filename
+ try:
+ if os.path.exists(pid_filename):
+ os.unlink(pid_filename)
+ f = open(pid_filename, 'w')
+ f.write(str(os.getpid()))
+ f.close()
+ except IOError:
+ pass
+
# Now that we've successfully setuid'd, we can log to
# somewhere other than stderr. Activate the configured logs:
if cfg.access is not None:
@@ -145,8 +169,6 @@
logger = cfg.eventlog()
startup_handler.flushBufferTo(logger)
- zLOG.LOG('Zope', zLOG.INFO, 'Ready to handle requests')
-
# Start Medusa, Ye Hass!
try:
import Lifetime
@@ -155,7 +177,7 @@
finally:
if not cfg.zserver_read_only_mode:
try:
- os.unlink(cfg.pid_filename)
+ os.unlink(pid_filename)
except OSError:
pass
try: