Commit 61e58cf7 authored by Chris McDonough's avatar Chris McDonough

Dumb bug in zdaemon fixed in which it would try to kill process numbers 1, 2, 3, 10, 12, and 15

when it caught a signal related to any of these signal numbers. ;-)  Instead, it
actually tries now to kill its child process with the same signal.

Pidfile handling improved.

When Zope is started under zdaemon, it no longer writes its own pidfile.  Instead, it passes in the path to Z2.pid to zdaemon as its pidfile name.  The 'zProcessManager.pid' file is no longer ever written.

This caused a change to the -Z option of z2.py which should be mostly backwards-compatible (unless people were relying on zProcessManager.pid to be written).  Now the -Z option is a boolean.  -Z1 means use a daemon.  -Z0 means dont.  The default is -Z1.

Write pidfiles out with trailing newlines.

Minor reorganization of "SignalPasser" code (move it from its own module into zdaemon).
parent b7e2a135
...@@ -25,18 +25,22 @@ Options: ...@@ -25,18 +25,22 @@ Options:
The location of the Zope installation. The location of the Zope installation.
The default is the location of this script, %(here)s. The default is the location of this script, %(here)s.
-Z path -Z 0 or 1
Unix only! This option is ignored on windows. UNIX only! This option is ignored on Windows.
If this option is specified, a separate managemnt process will This option controls whether a management process will be created
be created that restarts Zope after a shutdown (or crash). that restarts Zope after a shutdown or crash.
The path must point to a pid file that the process will record its
process id in. The path may be relative, in which case it will be If the argument to -Z is non-null (e.g. "-Z1" or "-Zyes"), a
relative to the Zope location. management process will be used. If the argument to -Z is "-", or
"0", (e.g. "-Z-" or "-Z0"), a management process will not be used.
On UNIX, the default behavior is to create a separate management
process (e.g. -Z1) if the -Z option is not specified.
To prevent use of a separate management process, provide an (Note: the -Z option in Zopes before Zope 2.6 used to be used to specify
empty string: -Z='' a pidfile name for the management process. This pidfile no longer
exists).
-t n -t n
...@@ -251,8 +255,6 @@ sys.setcheckinterval(500) ...@@ -251,8 +255,6 @@ sys.setcheckinterval(500)
program=sys.argv[0] program=sys.argv[0]
here=os.path.join(os.getcwd(), os.path.split(program)[0]) here=os.path.join(os.getcwd(), os.path.split(program)[0])
Zpid=''
######################################################################## ########################################################################
# Configuration section # Configuration section
...@@ -260,10 +262,6 @@ Zpid='' ...@@ -260,10 +262,6 @@ Zpid=''
## General configuration options ## General configuration options
## ##
# If you want run as a daemon, then uncomment the line below:
if sys.platform=='win32': Zpid=''
else: Zpid='zProcessManager.pid'
# This is the IP address of the network interface you want your servers to # This is the IP address of the network interface you want your servers to
# be visible from. This can be changed to '' to listen on all interfaces. # be visible from. This can be changed to '' to listen on all interfaces.
IP_ADDRESS='' IP_ADDRESS=''
...@@ -331,6 +329,9 @@ FCGI_PORT=None ...@@ -331,6 +329,9 @@ FCGI_PORT=None
# Detailed log file # Detailed log file
DETAILED_LOG_FILE='' DETAILED_LOG_FILE=''
# Use a daemon process
USE_DAEMON = 1
# #
######################################################################## ########################################################################
...@@ -391,6 +392,9 @@ try: ...@@ -391,6 +392,9 @@ try:
DEBUG=0 DEBUG=0
READ_ONLY=0 READ_ONLY=0
if sys.platform == 'win32':
USE_DAEMON = 0
# Get environment variables # Get environment variables
for a in args: for a in args:
...@@ -407,8 +411,10 @@ try: ...@@ -407,8 +411,10 @@ try:
for o, v in opts: for o, v in opts:
if o=='-z': here=v if o=='-z': here=v
elif o=='-Z': elif o=='-Z':
if v=='-': v='' if v in ('-', '0', ''):
Zpid=v USE_DAEMON=0
elif sys.platform != 'win32':
USE_DAEMON = 1
elif o=='-r': READ_ONLY=1 elif o=='-r': READ_ONLY=1
elif o=='-t': elif o=='-t':
try: v=int(v) try: v=int(v)
...@@ -473,8 +479,6 @@ except: ...@@ -473,8 +479,6 @@ except:
print "%s: %s" % (sys.exc_type, sys.exc_value) print "%s: %s" % (sys.exc_type, sys.exc_value)
sys.exit(1) sys.exit(1)
if sys.platform=='win32': Zpid=''
# #
######################################################################## ########################################################################
...@@ -529,13 +533,18 @@ if os.name == 'posix': ...@@ -529,13 +533,18 @@ if os.name == 'posix':
from Signals import Signals from Signals import Signals
Signals.registerZopeSignals() Signals.registerZopeSignals()
if Zpid and not READ_ONLY: # Location of the ZServer pid file. When Zope starts up it will write
# its PID to this file. If Zope is run under zdaemon control, zdaemon
# will write to this pidfile instead of Zope.
PID_FILE=os.path.join(CLIENT_HOME, 'Z2.pid')
if USE_DAEMON and not READ_ONLY:
import App.FindHomes import App.FindHomes
sys.ZMANAGED=1 sys.ZMANAGED=1
# zdaemon.run creates a process which "manages" the actual Zope # zdaemon.run creates a process which "manages" the actual Zope
# process (restarts it if it dies). The management process passes along # process (restarts it if it dies). The management process passes along
# signals that it receives to its child. # signals that it receives to its child.
zdaemon.run(sys.argv, os.path.join(CLIENT_HOME, Zpid)) zdaemon.run(sys.argv, os.path.join(CLIENT_HOME, PID_FILE))
os.chdir(CLIENT_HOME) os.chdir(CLIENT_HOME)
...@@ -578,11 +587,6 @@ try: ...@@ -578,11 +587,6 @@ try:
else: else:
LOG_PATH=LOG_FILE LOG_PATH=LOG_FILE
# Location of the ZServer pid file. When ZServer starts up it will write
# its PID to this file.
PID_FILE=os.path.join(CLIENT_HOME, 'Z2.pid')
# import ZServer stuff # import ZServer stuff
# First, we need to increase the number of threads # First, we need to increase the number of threads
...@@ -804,12 +808,10 @@ try: ...@@ -804,12 +808,10 @@ try:
'switch':'--icp'} 'switch':'--icp'}
raise raise
if not READ_ONLY: if not USE_DAEMON and not READ_ONLY:
if os.path.exists(PID_FILE): os.unlink(PID_FILE) if os.path.exists(PID_FILE): os.unlink(PID_FILE)
pf = open(PID_FILE, 'w') pf = open(PID_FILE, 'w')
pid=str(os.getpid()) pid='%s\n' % os.getpid()
try: pid=str(os.getppid())+' '+pid
except: pass
pf.write(pid) pf.write(pid)
pf.close() pf.close()
......
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