[Erp5-report] r42001 nicolas - in /erp5/trunk/utils/cloudooo/cloudooo/handler/ooo: ./ monitor/

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Jan 4 16:46:25 CET 2011


Author: nicolas
Date: Tue Jan  4 16:46:24 2011
New Revision: 42001

URL: http://svn.erp5.org?rev=42001&view=rev
Log:
Add new monitor which allows to stop OpenOffice daemon,
if after configurable amount of time it doesn't serve any requests.
Any new request will wake up daemon smoothly.

To enable it, put in your cloudooo.conf under section [app:main]:

# Duration in seconds
max_sleeping_duration = 300


Added:
    erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/monitor/sleeping_time.py
Modified:
    erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/handler.py
    erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/monitor/__init__.py

Modified: erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/handler.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/handler.py?rev=42001&r1=42000&r2=42001&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/handler.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/handler.py [utf8] Tue Jan  4 16:46:24 2011
@@ -39,6 +39,7 @@ from cloudooo.interfaces.handler import 
 from cloudooo.handler.ooo.mimemapper import mimemapper
 from cloudooo.handler.ooo.document import FileSystemDocument
 from cloudooo.handler.ooo.monitor.timeout import MonitorTimeout
+from cloudooo.handler.ooo.monitor import monitor_sleeping_time
 from cloudooo.utils.utils import logger
 from psutil import pid_exists
 
@@ -99,6 +100,8 @@ class OOHandler:
 
   def _subprocess(self, command):
     """Run one procedure"""
+    if monitor_sleeping_time is not None:
+      monitor_sleeping_time.touch()
     try:
       self._startTimeout()
       process = Popen(command,

Modified: erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/monitor/__init__.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/monitor/__init__.py?rev=42001&r1=42000&r2=42001&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/monitor/__init__.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/monitor/__init__.py [utf8] Tue Jan  4 16:46:24 2011
@@ -1,25 +1,34 @@
 from request import MonitorRequest
 from memory import MonitorMemory
+from sleeping_time import MonitorSpleepingTime
 from cloudooo.handler.ooo.application.openoffice import openoffice
 
 monitor_request = None
 monitor_memory = None
-
+monitor_sleeping_time = None
 
 def load(local_config):
   """Start the monitors"""
+  monitor_interval = int(local_config.get('monitor_interval'))
   global monitor_request
   monitor_request = MonitorRequest(openoffice,
-                              int(local_config.get('monitor_interval')),
+                              monitor_interval,
                               int(local_config.get('limit_number_request')))
   monitor_request.start()
 
   if bool(local_config.get('enable_memory_monitor')):
     global monitor_memory
     monitor_memory = MonitorMemory(openoffice,
-                                  int(local_config.get('monitor_interval')),
+                                  monitor_interval,
                                   int(local_config.get('limit_memory_used')))
     monitor_memory.start()
+  time_before_sleep = int(local_config.get('max_sleeping_duration', 0))
+  if time_before_sleep:
+    global monitor_sleeping_time
+    monitor_sleeping_time = MonitorSpleepingTime(openoffice,
+                                                 monitor_interval,
+                                                 time_before_sleep)
+    monitor_sleeping_time.start()
   return
 
 
@@ -29,10 +38,13 @@ def stop():
     monitor_request.terminate()
   if monitor_memory:
     monitor_memory.terminate()
+  if monitor_sleeping_time is not None:
+    monitor_sleeping_time.terminate()
   clear()
 
 
 def clear():
-  global monitor_request, monitor_memory
+  global monitor_request, monitor_memory, monitor_sleeping_time
   monitor_request = None
   monitor_memory = None
+  monitor_sleeping_time = None

Added: erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/monitor/sleeping_time.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/monitor/sleeping_time.py?rev=42001&view=auto
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/monitor/sleeping_time.py (added)
+++ erp5/trunk/utils/cloudooo/cloudooo/handler/ooo/monitor/sleeping_time.py [utf8] Tue Jan  4 16:46:24 2011
@@ -0,0 +1,75 @@
+##############################################################################
+#
+# Copyright (c) 2009-2011 Nexedi SA and Contributors. All Rights Reserved.
+#                    Nicolas Delaby <nicolas at nexedi.com>
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsibility of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# guarantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+##############################################################################
+
+from monitor import Monitor
+from threading import Thread
+import psutil
+from cloudooo.utils.utils import logger
+from time import sleep, time
+
+
+class MonitorSpleepingTime(Monitor, Thread):
+  """Usefull to stop daemon if not beeing used after duration of time
+  """
+
+  def __init__(self, openoffice, interval, sleeping_time):
+    """Expects to receive an object that implements the interfaces IApplication
+    and ILockable, the limit of memory usage that the openoffice can use and
+    the interval to check the object."""
+    Monitor.__init__(self, openoffice, interval)
+    Thread.__init__(self)
+    self.sleeping_time = sleeping_time
+    self._touched_at = time()
+
+  def start(self):
+    self.status_flag = True
+    Thread.start(self)
+
+  def touch(self):
+    """Restart countdown
+    """
+    logger.debug("Touch MonitorSpleepingTime")
+    self._touched_at = time()
+
+  def run(self):
+    """Start monitoring process.
+    Stop daemon if running and not touch after sleeping duration
+    """
+    logger.debug("Start MonitorSpleepingTime")
+    while self.status_flag:
+      current_time = time()
+      if self.openoffice.status() and\
+        (self._touched_at + self.sleeping_time) <= current_time:
+        logger.debug("Stopping OpenOffice after sleeping time of %is" %\
+                                                            self.sleeping_time)
+        self.openoffice.acquire()
+        self.openoffice.stop()
+        self.openoffice.release()
+      sleep(self.interval)
+    logger.debug("Stop MonitorSpleepingTime")
+



More information about the Erp5-report mailing list