[Erp5-report] r34958 rafael - /erp5/trunk/utils/oood/pidproxy.py

nobody at svn.erp5.org nobody at svn.erp5.org
Mon May 3 18:53:15 CEST 2010


Author: rafael
Date: Mon May  3 18:53:15 2010
New Revision: 34958

URL: http://svn.erp5.org?rev=34958&view=rev
Log:
  This script is temporary, as soon as oood supports works into
  buildout/supervisor nicelly, this script should be removed.

  This script is part of supervisor (http://pypi.python.org/pypi/supervisor)
  and it should be used only for handle oood into ERP5 Appliance environment.

  Why this? Sometimes the OOOD process does not end SIGTERM is received (sent by
  supervisor). Supervisor after SIGTERM (and a configureable delay) and use
  SIGKILL in pidproxy process make zumbies process into the server. This signal
  should be sent to "runserw --start" process instead.

  This change kill runserw (set at ERP5 Appliance configuration), using SIGKILL
  to make sure the process will stop (Too brutal but more reliable).


Added:
    erp5/trunk/utils/oood/pidproxy.py   (with props)

Added: erp5/trunk/utils/oood/pidproxy.py
URL: http://svn.erp5.org/erp5/trunk/utils/oood/pidproxy.py?rev=34958&view=auto
==============================================================================
--- erp5/trunk/utils/oood/pidproxy.py (added)
+++ erp5/trunk/utils/oood/pidproxy.py [utf8] Mon May  3 18:53:15 2010
@@ -1,0 +1,101 @@
+#!/usr/bin/env python
+##############################################################################
+#
+# Copyright (c) 2007 Agendaless Consulting and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the BSD-like license at
+# http://www.repoze.org/LICENSE.txt.  A copy of the license should accompany
+# this distribution.  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL
+# EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO,
+# THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND
+# FITNESS FOR A PARTICULAR PURPOSE
+#
+##############################################################################
+
+"""
+  This script is temporary, as soon as oood supports works into
+  buildout/supervisor nicelly, this script should be removed.
+
+  This script is part of supervisor (http://pypi.python.org/pypi/supervisor) 
+  and it should be used only for handle oood into ERP5 Appliance environment.
+
+  Why this? Sometimes the OOOD process does not end SIGTERM is received (sent by
+  supervisor). Supervisor after SIGTERM (and a configureable delay) and use 
+  SIGKILL in pidproxy process make zumbies process into the server. This signal
+  should be sent to "runserw --start" process instead.
+
+  This change kill runserw (set at ERP5 Appliance configuration), using SIGKILL
+  to make sure the process will stop (Too brutal but more reliable). 
+"""
+
+""" An executable which proxies for a subprocess; upon a signal, it sends that
+signal to the process identified by a pidfile. """
+
+import os
+import sys
+import signal
+import time
+
+class PidProxy:
+    pid = None
+    def __init__(self, args):
+        self.setsignals()
+        try:
+            self.pidfile, cmdargs = args[1], args[2:]
+            self.command = os.path.abspath(cmdargs[0])
+            self.cmdargs = cmdargs
+        except (ValueError, IndexError):
+            self.usage()
+            sys.exit(1)
+
+    def go(self):
+        self.pid = os.spawnv(os.P_NOWAIT, self.command, self.cmdargs)
+        while 1:
+            time.sleep(5)
+            try:
+                pid, sts = os.waitpid(-1, os.WNOHANG)
+            except OSError:
+                pid, sts = None, None
+            if pid:
+                break
+
+    def usage(self):
+        print "pidproxy.py <pidfile name> <command> [<cmdarg1> ...]"
+
+    def setsignals(self):
+        signal.signal(signal.SIGTERM, self.passtochild)
+        signal.signal(signal.SIGHUP, self.passtochild)
+        signal.signal(signal.SIGINT, self.passtochild)
+        signal.signal(signal.SIGUSR1, self.passtochild)
+        signal.signal(signal.SIGUSR2, self.passtochild)
+        signal.signal(signal.SIGCHLD, self.reap)
+
+    def reap(self, sig, frame):
+        # do nothing, we reap our child synchronously
+        pass
+
+    def passtochild(self, sig, frame):
+        try:
+            pid = int(open(self.pidfile, 'r').read().strip())
+        except:
+            pid = None
+            print "Can't read child pidfile %s!" % self.pidfile
+            return
+        # XXX Start DIFF
+        # Force that program will finish.
+        if sig in [signal.SIGTERM, signal.SIGINT, signal.SIGQUIT]:
+            os.kill(pid, signal.SIGKILL)
+        else:
+            os.kill(pid, sig)
+        #os.kill(pid, sig)
+        # XXX Stop DIFF
+        if sig in [signal.SIGTERM, signal.SIGINT, signal.SIGQUIT]:
+            sys.exit(0)
+
+def main():
+    pp = PidProxy(sys.argv)
+    pp.go()
+
+if __name__ == '__main__':
+    main() 

Propchange: erp5/trunk/utils/oood/pidproxy.py
------------------------------------------------------------------------------
    svn:executable = *




More information about the Erp5-report mailing list