[Erp5-report] r35153 rafael - /erp5/trunk/buildout/templates/oood-runserw.in
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue May 11 00:07:04 CEST 2010
Author: rafael
Date: Tue May 11 00:07:03 2010
New Revision: 35153
URL: http://svn.erp5.org?rev=35153&view=rev
Log:
Refactor script to start/stop oood in an appropriated way and make sure the ood will be really stopped after this commend is killed.
Modified:
erp5/trunk/buildout/templates/oood-runserw.in
Modified: erp5/trunk/buildout/templates/oood-runserw.in
URL: http://svn.erp5.org/erp5/trunk/buildout/templates/oood-runserw.in?rev=35153&r1=35152&r2=35153&view=diff
==============================================================================
--- erp5/trunk/buildout/templates/oood-runserw.in [utf8] (original)
+++ erp5/trunk/buildout/templates/oood-runserw.in [utf8] Tue May 11 00:07:03 2010
@@ -1,13 +1,70 @@
-#!/bin/sh
+#!${configuration:openoffice_python}
-# Verify if there is another oood running and flush if not
-# This will stop previous open offices running in the past.
-if [ ! -f ${configuration:oood_pid}];
-then
- PYTHONPATH=${configuration:openoffice_uno} ${configuration:openoffice_python} ${software_definition:oood_software}/start.py --flush > /dev/null 2>&1 /dev/null
-fi
+import signal
+import time
+import subprocess
+import sys
+import os
-PYTHONPATH=${configuration:openoffice_uno} ${configuration:openoffice_python} ${software_definition:oood_software}/runserw.py $@
+PID_FILE = "${configuration:oood_pid}"
-# After the previous command finish (--start or --stop), call start.py flush, this prevents leave openoffice and xvfb running after stop.
-PYTHONPATH=${configuration:openoffice_uno} ${configuration:openoffice_python} ${software_definition:oood_software}/start.py --flush > /dev/null 2>&1 /dev/null
+OOOD_COMMAND = " PYTHONPATH=${configuration:openoffice_uno} " + \
+ " ${configuration:openoffice_python} " + \
+ " ${software_definition:oood_software}/runserw.py "
+
+FLUSH_COMMAND = " PYTHONPATH=${configuration:openoffice_uno} " + \
+ " ${configuration:openoffice_python} " + \
+ " ${software_definition:oood_software}/start.py " + \
+ " --flush > /dev/null 2>&1 /dev/null"
+
+class Oood:
+ pid = None
+ def __init__(self):
+ self.setsignals()
+
+ def run(self):
+ subprocess.call(OOOD_COMMAND + "--start > /dev/null 2>&1 /dev/null &",
+ shell=True)
+ subprocess.call(FLUSH_COMMAND, shell=True)
+ while 1:
+ if os.path.exists(PID_FILE):
+ self.pid = int(open(PID_FILE, "r").read())
+ time.sleep(40)
+ time.sleep(5)
+
+ def setsignals(self):
+ signal.signal(signal.SIGTERM, self.stop)
+ signal.signal(signal.SIGHUP, self.stop)
+ signal.signal(signal.SIGINT, self.stop)
+ signal.signal(signal.SIGUSR1, self.stop)
+ signal.signal(signal.SIGUSR2, self.stop)
+
+ def stop(self, sig, frame):
+
+ if os.path.exists(PID_FILE):
+ self.pid = int(open(PID_FILE, "r").read())
+ #print self.pid
+ else:
+ print "Pid File does not exist!"
+
+ subprocess.call(OOOD_COMMAND + "--stop > /dev/null 2>&1 /dev/null ",
+ shell=True)
+ subprocess.call(FLUSH_COMMAND, shell=True)
+ if self.pid is not None:
+ try:
+ os.kill(self.pid, 9)
+ print "Kill pid (%s)" % self.pid
+ except OSError:
+ #print "Pid (%s) already stopped. " % self.pid
+ pass
+ # Ignore is ok, it means stop command works.
+
+ sys.exit(0)
+
+
+def main():
+ pp = Oood()
+ pp.run()
+
+if __name__ == '__main__':
+ main()
More information about the Erp5-report
mailing list