Merge "Check for stale PID lock when starting"

This commit is contained in:
Jenkins 2014-06-14 18:23:55 +00:00 committed by Gerrit Code Review
commit 0dc4b59b7d

View File

@ -16,6 +16,7 @@
import argparse
import daemon
import errno
import extras
# as of python-daemon 1.6 it doesn't bundle pidlockfile anymore
@ -54,6 +55,28 @@ def stack_dump_handler(signum, frame):
signal.signal(signal.SIGUSR2, stack_dump_handler)
def is_pidfile_stale(pidfile):
""" Determine whether a PID file is stale.
Return 'True' ("stale") if the contents of the PID file are
valid but do not match the PID of a currently-running process;
otherwise return 'False'.
"""
result = False
pidfile_pid = pidfile.read_pid()
if pidfile_pid is not None:
try:
os.kill(pidfile_pid, 0)
except OSError as exc:
if exc.errno == errno.ESRCH:
# The specified PID does not exist
result = True
return result
class NodePoolDaemon(object):
def __init__(self):
self.args = None
@ -118,6 +141,8 @@ def main():
return(0)
pid = pid_file_module.TimeoutPIDLockFile(npd.args.pidfile, 10)
if is_pidfile_stale(pid):
pid.break_lock()
if npd.args.nodaemon:
npd.main()