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

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Nov 30 11:53:31 CET 2006


Author: kevin
Date: Thu Nov 30 11:53:30 2006
New Revision: 11533

URL: http://svn.erp5.org?rev=11533&view=rev
Log:
Launch open office instance in virtual display.
Rename pid_dir to run_dir.

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=11533&r1=11532&r2=11533&view=diff
==============================================================================
--- erp5/trunk/utils/oood/start.py (original)
+++ erp5/trunk/utils/oood/start.py Thu Nov 30 11:53:30 2006
@@ -33,8 +33,12 @@
 # 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, glob  # Standard python libs
-import lib, config         # ood python libs
+# Standard python libs
+import getopt, time, glob
+from commands import getstatusoutput
+# ood python libs
+import lib, config
+
 
 
 """
@@ -62,25 +66,31 @@
   """
   _l("Starting...", i, 0)
   instance_port = config.pool_port_range_start + i
-  cmd = '%s/soffice' % config.uno_path
-  params = [ '-headless'
-           , '-accept=socket,host=%s,port=%d;urp;' % (config.pool_host, instance_port)
-           , '-env:UserInstallation=$SYSUSERCONFIG/./tmp/oood_instance_%d' % i
-           #, '-env:UserInstallation=%s/./oood_instance_%d' % (config.pid_dir, i)
-           , '-nologo'
-           , '-nodefault'
-           , '-norestore'
-           ]
-  pid = os.spawnvp(os.P_NOWAIT, cmd, params)
+  BIN = "soffice"
+  cmd = '%s/%s' % (config.uno_path, BIN)
+  # "'-display :%d' % config.virtual_display_id" argument is not working, that's why we use
+  # environnment variable. See "man xhost" for more details.
+  new_context = os.environ
+  new_context['DISPLAY'] = ":99"
+  args_and_env = [ BIN  # First arg is always the name of the binary software we execute
+                 , '-headless'
+                 , '-nologo'
+                 , '-nodefault'
+                 , '-norestore'
+                 , '-accept=socket,host=%s,port=%d;urp;' % (config.pool_host, instance_port)
+                 , '-env:UserInstallation=$SYSUSERCONFIG/./tmp/oood_instance_%d' % i
+                 , new_context
+                 ]
+  pid = os.spawnlpe(os.P_NOWAIT, cmd, *args_and_env)
   _l("Listening at %s:%s" % (config.pool_host, instance_port), i, 0)
-  pidfile = os.path.join(config.pid_dir, 'instance_%d.pid' % i)
+  pidfile = os.path.join(config.run_dir, 'instance_%d.pid' % i)
   open(pidfile, 'w').write(str(pid))
   _l("Started as process  %s" % pid, i, 0)
 
 
 def killInstance(i):
   _l("Kill requested", i, 1)
-  pid_file_path = os.path.join(config.pid_dir, 'instance_%s.pid' % i)
+  pid_file_path = os.path.join(config.run_dir, 'instance_%s.pid' % i)
   if os.path.exists(pid_file_path):
     pid_file = open(pid_file_path, 'r')
     instance_master_pid = int(pid_file.read())
@@ -126,7 +136,7 @@
   lib.log("Pool - Flush requested: kill all instances", 1)
   # 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):
+  for pid_file in glob.glob('%s*' % config.run_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')])
@@ -136,6 +146,38 @@
   for i in range(max_pool_size):
     killInstance(i)
   lib.log("Pool - Flushed: all instances killed", 0)
+
+
+
+### Generate Xvfb command
+virtual_display_cmd = "Xvfb -ac :%s -screen 0 800x600x16 -fbdir %s" % ( config.virtual_display_id
+                                                                      , config.run_dir
+                                                                      )
+
+def startVirtualFrameBuffer():
+  """
+    This method start a virtual frame buffer (Xvfb)
+  """
+  killVirtualFrameBuffer()
+  os.system("%s &" % virtual_display_cmd)
+  lib.log("Pool - Virtual frame buffer started", 0)
+
+
+def killVirtualFrameBuffer():
+  """
+    This method kill the virtual frame buffer (Xvfb)
+  """
+  # Do the shell command
+  result = getstatusoutput("ps ax | grep '%s'" % (virtual_display_cmd))
+  # Search the running process
+  killed = False
+  for process in result[1].splitlines():
+    if process.find(virtual_display_cmd) != -1 and process.find('grep') == -1:
+      pid = int(process.strip().split(' ')[0])
+      os.kill(pid, 9)
+      killed = True
+  if killed:
+    lib.log("Pool - Virtual frame buffer killed", 0)
 
 
 def showPoolStatus():
@@ -187,14 +229,16 @@
       usage()
       sys.exit(0)
     elif o in ("-i", "--init"):
+      startVirtualFrameBuffer()
       initPool()
       sys.exit(0)
     elif o in ("-f", "--flush"):
       flushPool()
+      killVirtualFrameBuffer()
       sys.exit(0)
     elif o in ("-s", "--status", "--stat"):
       showPoolStatus()
       sys.exit(0)
 
   # Exit on general error
-  sys.exit(1)
+  sys.exit(1)




More information about the Erp5-report mailing list