[Erp5-report] r22074 - /erp5/trunk/utils/oood/runserw.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Jun 30 11:57:02 CEST 2008


Author: jerome
Date: Mon Jun 30 11:56:58 2008
New Revision: 22074

URL: http://svn.erp5.org?rev=22074&view=rev
Log:
check for stale lock file on startup

Modified:
    erp5/trunk/utils/oood/runserw.py

Modified: erp5/trunk/utils/oood/runserw.py
URL: http://svn.erp5.org/erp5/trunk/utils/oood/runserw.py?rev=22074&r1=22073&r2=22074&view=diff
==============================================================================
--- erp5/trunk/utils/oood/runserw.py (original)
+++ erp5/trunk/utils/oood/runserw.py Mon Jun 30 11:56:58 2008
@@ -32,6 +32,7 @@
 import getopt
 import sys
 import os
+import errno
 import signal
 import atexit
 import base64
@@ -284,11 +285,23 @@
     # Create a lock file to not run more than one server and to save the pid
     lock_file_path = os.path.join(config.run_dir, 'server%s_pid.lock'%offset_str)
     if os.path.exists(lock_file_path):
-      message = "Server is already running (lock file %s exists)" % \
-                                           lock_file_path
-      Log.info(message)
-      print message
-      sys.exit(1)
+      f = file(lock_file_path, 'r')
+      try:
+        pid = int(f.read())
+      finally:
+        f.close()
+      try:
+        os.kill(pid, 0)
+      except OSError, err:
+        if err[0] == errno.ESRCH:
+          Log.info('Removing stale lock file %s' % lock_file_path)
+          os.unlink(lock_file_path)
+      else:
+        message = "Server is already running (lock file %s exists)" % \
+                                             lock_file_path
+        Log.info(message)
+        print message
+        sys.exit(1)
 
     lock_file = open(lock_file_path, 'w')
     server_pid = os.getpid()




More information about the Erp5-report mailing list