[Erp5-report] r11432 - /erp5/trunk/utils/oood/start.py

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Nov 22 14:06:42 CET 2006


Author: kevin
Date: Wed Nov 22 14:06:40 2006
New Revision: 11432

URL: http://svn.erp5.org?rev=11432&view=rev
Log:
Clean previous un-killed OOo instance (could happend when config file is changed)

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

Modified: erp5/trunk/utils/oood/start.py
URL: http://svn.erp5.org/erp5/trunk/utils/oood/start.py?rev=11432&r1=11431&r2=11432&view=diff
==============================================================================
--- erp5/trunk/utils/oood/start.py (original)
+++ erp5/trunk/utils/oood/start.py Wed Nov 22 14:06:40 2006
@@ -33,8 +33,8 @@
 # XXX Is this magical things make oood_home parameter useless in oood config file ?
 sys.path.append(os.path.abspath(os.getcwd()))
 
-import getopt, time  # Standard python libs
-import lib, config   # ood python libs
+import getopt, time, glob  # Standard python libs
+import lib, config         # ood python libs
 
 """
   Starts OOo instances to populate the pool.
@@ -43,7 +43,6 @@
     by OOo on startup in the ~/tmp folder of the running user.
   TODO: use lock file (like /var/run/oood/pool.lock) for proper pool startup managment.
 """
-
 
 
 def _l(msg, instance_id, level):
@@ -78,7 +77,7 @@
 
 def killInstance(i):
   _l("Kill requested", i, 1)
-  pid_file_path = os.path.join(config.pid_dir, 'instance_%d.pid' % i)
+  pid_file_path = os.path.join(config.pid_dir, 'instance_%s.pid' % i)
   if os.path.exists(pid_file_path):
     _l("Is still running or was not properly shutdown: Kill it", i, 0)
     pid_file = open(pid_file_path, 'r')
@@ -112,10 +111,19 @@
 
 
 def stopAll():
-  lib.log("Pool - Stop all %s instances" % config.pool_size, 0)
-  for i in range(config.pool_size):
+  lib.log("Pool - Stop all instances", 0)
+  # pool_size can change dynamiccaly, so clear every running OOo intance
+  max_pool_size = config.pool_size
+  for pid_file in glob.glob('%s*' % config.pid_dir):
+    file_name = os.path.basename(pid_file)
+    if file_name.startswith('instance_') and file_name.endswith('.pid'):
+      instance_id = int(file_name[len('instance_'):len(file_name)-len('.pid')])
+      old_pool_size = instance_id + 1
+      if old_pool_size > max_pool_size:
+        max_pool_size = old_pool_size
+  for i in range(max_pool_size):
     killInstance(i)
-  lib.log("Pool - All %s instances flushed away" % config.pool_size, 0)
+  lib.log("Pool - All instances flushed away", 0)
 
 
 def showStatus():




More information about the Erp5-report mailing list