Enhanced do_start() implementation in Python management script
authordbs <dbs@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 9 Nov 2010 18:17:50 +0000 (18:17 +0000)
committerdbs <dbs@9efc2488-bf62-4759-914b-345cdb29e865>
Tue, 9 Nov 2010 18:17:50 +0000 (18:17 +0000)
Unclean shutdowns and fork() misery can create PID files that have
no actual process behind them. Instead of just trusting the PID file, check
for the running PID; if the process is not running, then remove the PID file
and actually start the service.

git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@2070 9efc2488-bf62-4759-914b-345cdb29e865

src/python/opensrf.py.in

index bd6c4f0..809946b 100755 (executable)
@@ -113,8 +113,13 @@ def do_start(service):
         return
 
     if os.path.exists(pidfile):
-        print "* service %s already running" % service
-        return
+        try:
+            pid_fd = open(pidfile, 'r')
+            alive = os.getsid(int(pid_fd.read()))
+            print "* service %s already running" % service
+            return
+        except OSError:
+            os.remove(pidfile)
 
     print "* starting %s" % service