handle stale pid file
This commit is contained in:
@@ -26,6 +26,7 @@ import syslog
|
|||||||
|
|
||||||
PORT = 50003
|
PORT = 50003
|
||||||
INTERVAL = 10
|
INTERVAL = 10
|
||||||
|
PIDFILE = '/tmp/hbc.pid'
|
||||||
DBG = True
|
DBG = True
|
||||||
|
|
||||||
sock = None
|
sock = None
|
||||||
@@ -260,12 +261,32 @@ if msgonly:
|
|||||||
#
|
#
|
||||||
syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_DAEMON)
|
syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_DAEMON)
|
||||||
if fdaemon:
|
if fdaemon:
|
||||||
print "daemoinizing... %s" % os.getpid()
|
|
||||||
|
|
||||||
|
pidfile = daemon.pidfile.TimeoutPIDLockFile(PIDFILE, acquire_timeout=-1)
|
||||||
|
try:
|
||||||
|
opid = pidfile.read_pid()
|
||||||
|
except:
|
||||||
|
opid = None
|
||||||
|
if verbose: print "opid %s" % opid
|
||||||
|
|
||||||
|
if opid:
|
||||||
|
try:
|
||||||
|
os.kill(opid, 0)
|
||||||
|
is_running = True
|
||||||
|
except:
|
||||||
|
is_running = False
|
||||||
|
if verbose: print "is_running %s" % is_running
|
||||||
|
if is_running:
|
||||||
|
print "process still alive %s" % opid
|
||||||
|
sys.exit(1)
|
||||||
|
print "warning: stale pid file removed"
|
||||||
|
os.unlink(PIDFILE)
|
||||||
|
|
||||||
|
print "daemoinizing... %s" % os.getpid()
|
||||||
context = daemon.DaemonContext(
|
context = daemon.DaemonContext(
|
||||||
working_directory='/tmp',
|
working_directory='/tmp',
|
||||||
umask=0o002,
|
umask=0o002,
|
||||||
pidfile=daemon.pidfile.TimeoutPIDLockFile('/tmp/hbc.pid', acquire_timeout=-1),
|
pidfile=pidfile,
|
||||||
)
|
)
|
||||||
|
|
||||||
context.signal_map = {
|
context.signal_map = {
|
||||||
|
|||||||
Reference in New Issue
Block a user