Commit 837c63e8 authored by Chris McDonough's avatar Chris McDonough

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.
parent ff66de77
...@@ -50,6 +50,7 @@ def start_zope(cfg): ...@@ -50,6 +50,7 @@ def start_zope(cfg):
# set up our initial logging environment (log everything to stderr # set up our initial logging environment (log everything to stderr
# if we're not in debug mode). # if we're not in debug mode).
import zLOG import zLOG
import logging
# don't initialize the event logger from the environment # don't initialize the event logger from the environment
zLOG._call_initialize = 0 zLOG._call_initialize = 0
...@@ -76,6 +77,9 @@ def start_zope(cfg): ...@@ -76,6 +77,9 @@ def start_zope(cfg):
# set up our event logger temporarily with a startup handler # set up our event logger temporarily with a startup handler
event_logger = zLOG.EventLogger.EventLogger.logger event_logger = zLOG.EventLogger.EventLogger.logger
event_logger.addHandler(startup_handler) 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 # set a locale if one has been specified in the config
if cfg.locale: if cfg.locale:
...@@ -104,7 +108,7 @@ def start_zope(cfg): ...@@ -104,7 +108,7 @@ def start_zope(cfg):
% (server.servertype(),e[1])) % (server.servertype(),e[1]))
cfg.servers = servers 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': if os.name == 'posix':
do_posix_stuff(cfg) do_posix_stuff(cfg)
...@@ -112,9 +116,18 @@ def start_zope(cfg): ...@@ -112,9 +116,18 @@ def start_zope(cfg):
import Zope import Zope
Zope.startup() 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: if not cfg.zserver_read_only_mode:
# lock_file is used for the benefit of zctl, so it can tell whether # lock_file is used for the benefit of zctl-like systems, so they
# Zope is already running before attempting to fire it off again. # 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 # We aren't concerned about locking the file to protect against
# other Zope instances running from our CLIENT_HOME, we just # other Zope instances running from our CLIENT_HOME, we just
# try to lock the file to signal that zctl should not try to # try to lock the file to signal that zctl should not try to
...@@ -132,6 +145,17 @@ def start_zope(cfg): ...@@ -132,6 +145,17 @@ def start_zope(cfg):
except IOError: except IOError:
pass 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 # Now that we've successfully setuid'd, we can log to
# somewhere other than stderr. Activate the configured logs: # somewhere other than stderr. Activate the configured logs:
if cfg.access is not None: if cfg.access is not None:
...@@ -145,8 +169,6 @@ def start_zope(cfg): ...@@ -145,8 +169,6 @@ def start_zope(cfg):
logger = cfg.eventlog() logger = cfg.eventlog()
startup_handler.flushBufferTo(logger) startup_handler.flushBufferTo(logger)
zLOG.LOG('Zope', zLOG.INFO, 'Ready to handle requests')
# Start Medusa, Ye Hass! # Start Medusa, Ye Hass!
try: try:
import Lifetime import Lifetime
...@@ -155,7 +177,7 @@ def start_zope(cfg): ...@@ -155,7 +177,7 @@ def start_zope(cfg):
finally: finally:
if not cfg.zserver_read_only_mode: if not cfg.zserver_read_only_mode:
try: try:
os.unlink(cfg.pid_filename) os.unlink(pid_filename)
except OSError: except OSError:
pass pass
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment