handle stale pid file
This commit is contained in:
@@ -24,8 +24,9 @@ import daemon.pidfile
|
||||
import syslog
|
||||
|
||||
|
||||
PORT=50003
|
||||
INTERVAL=10
|
||||
PORT = 50003
|
||||
INTERVAL = 10
|
||||
PIDFILE = '/tmp/hbc.pid'
|
||||
DBG = True
|
||||
|
||||
sock = None
|
||||
@@ -260,12 +261,32 @@ if msgonly:
|
||||
#
|
||||
syslog.openlog(logoption=syslog.LOG_PID, facility=syslog.LOG_DAEMON)
|
||||
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(
|
||||
working_directory='/tmp',
|
||||
umask=0o002,
|
||||
pidfile=daemon.pidfile.TimeoutPIDLockFile('/tmp/hbc.pid', acquire_timeout=-1),
|
||||
pidfile=pidfile,
|
||||
)
|
||||
|
||||
context.signal_map = {
|
||||
|
||||
Reference in New Issue
Block a user