[nanny/win32: 72/75] Hard stop of reactor if it's Window Service



commit 6807cf1978b0612b6d4d6002b0f92d265120da37
Author: Roberto Majadas <roberto majadas openshine com>
Date:   Mon Nov 1 20:13:15 2010 +0100

    Hard stop of reactor if it's Window Service

 daemon/NannyService.py |   33 +++++++++++++++++++++++++++------
 daemon/src/Daemon.py   |    8 +++++++-
 2 files changed, 34 insertions(+), 7 deletions(-)
---
diff --git a/daemon/NannyService.py b/daemon/NannyService.py
index 2990a72..ad26006 100644
--- a/daemon/NannyService.py
+++ b/daemon/NannyService.py
@@ -55,7 +55,10 @@ def main():
                                   app_service.stopService)
 
     #Reactor Run
-    reactor.run()
+    if not hasattr(sys, "frozen") :
+        reactor.run()
+    else:
+        reactor.run(installSignalHandlers=0)
 
 class NannyService (win32serviceutil.ServiceFramework):
     _svc_name_ = "NannyService"
@@ -78,20 +81,38 @@ class NannyService (win32serviceutil.ServiceFramework):
         win32event.SetEvent(self.hWaitStop)
 
     def SvcDoRun(self):
-        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
-                              servicemanager.PYS_SERVICE_STARTED,
-                              (self._svc_name_,''))
+        import servicemanager
+
         self.CheckForQuit()
         pythoncom.CoInitialize()
+
         sys.stdout = self.log
         sys.stderr = self.log
-        self.main()
+        
+        #Start UP application
+        import nanny.daemon
+        application = service.Application('nanny')
+        self.daemon = nanny.daemon.Daemon(application)
+        
+        app_service = service.IService(application)
+        app_service.privilegedStartService()
+        app_service.startService()
+        reactor.addSystemEventTrigger('before', 'shutdown',
+                                      app_service.stopService)
+        
+        #Reactor Run
+        if not hasattr(sys, "frozen") :
+            reactor.run()
+        else:
+            reactor.run(installSignalHandlers=0)
 
     def CheckForQuit(self):
             retval = win32event.WaitForSingleObject(self.hWaitStop, 10)
             if not retval == win32event.WAIT_TIMEOUT:
-                # Received Quit from Win32
+                print " Received Quit from Win32"
+                self.daemon.win32_service_stop()
                 reactor.stop()
+                print "STOP"
                 self.log.close()
                 pythoncom.CoUninitialize()
                 
diff --git a/daemon/src/Daemon.py b/daemon/src/Daemon.py
index 01b99d3..2b3daaf 100644
--- a/daemon/src/Daemon.py
+++ b/daemon/src/Daemon.py
@@ -46,4 +46,10 @@ class Daemon :
             from twisted.internet import reactor
             start_pyro_bus(self.quarterback)
         
-
+    def win32_service_stop(self):
+        self.quarterback.win32top.stop()
+        self.quarterback.firewall_filter.stop()
+        self.quarterback.filter_manager.stop()
+        self.quarterback.webcontent_filter.stop()
+        self.quarterback.session_filter.stop()
+    



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]