Author: damoxc

Revision: 5611

Log:
        change it so starting in ssl mode is left up to the server
add a stop method that doesn't stop the reactor

Diff:
Modified: trunk/deluge/ui/web/server.py
===================================================================
--- trunk/deluge/ui/web/server.py       2009-08-03 14:40:24 UTC (rev 5610)
+++ trunk/deluge/ui/web/server.py       2009-08-03 15:40:58 UTC (rev 5611)
@@ -435,6 +435,7 @@
                 os.rename(old_config.config_file, backup_path)
                 del old_config
 
+        self.socket = None
         self.top_level = TopLevel()
         self.site = server.Site(self.top_level)
         self.port = self.config["port"]
@@ -444,47 +445,57 @@
         self.web_api = WebApi()
         self.auth = Auth()
 
+        # Initalize the plugins
+        self.plugins = PluginManager()
+    
+    def install_signal_handlers(self):
         # Since twisted assigns itself all the signals may as well make
         # use of it.
-        reactor.addSystemEventTrigger("after", "shutdown", self.shutdown)
-
-        # Twisted doesn't handle windows specific signals so we still
-        # need to attach to those to handle the close correctly.
-        if common.windows_check():
-            from win32api import SetConsoleCtrlHandler
-            from win32con import CTRL_CLOSE_EVENT, CTRL_SHUTDOWN_EVENT
-            def win_handler(ctrl_type):
-                log.debug("ctrl type: %s", ctrl_type)
-                if ctrl_type == CTRL_CLOSE_EVENT or \
-                   ctrl_type == CTRL_SHUTDOWN_EVENT:
-                    self.shutdown()
-                    return 1
+        reactor.addSystemEventTrigger("after", "shutdown", self.shutdown)
+
+        # Twisted doesn't handle windows specific signals so we still
+        # need to attach to those to handle the close correctly.
+        if common.windows_check():
+            from win32api import SetConsoleCtrlHandler
+            from win32con import CTRL_CLOSE_EVENT, CTRL_SHUTDOWN_EVENT
+            def win_handler(ctrl_type):
+                log.debug("ctrl type: %s", ctrl_type)
+                if ctrl_type == CTRL_CLOSE_EVENT or \
+                   ctrl_type == CTRL_SHUTDOWN_EVENT:
+                    self.shutdown()
+                    return 1
             SetConsoleCtrlHandler(win_handler)
 
-        # Initalize the plugins
-        self.plugins = PluginManager()
-
     def start(self):
         log.info("%s %s.", _("Starting server in PID"), os.getpid())
-        reactor.listenTCP(self.port, self.site)
+        if self.https:
+            self.start_ssl()
+        else:
+            self.start_normal()
+
+        self.plugins.enable_plugins()
+        reactor.run()
+        
+    def start_normal(self):
+        self.socket = reactor.listenTCP(self.port, self.site)
         log.info("serving on %s:%s view at http://127.0.0.1:%s";, "0.0.0.0",
             self.port, self.port)
-        self.plugins.enable_plugins()
-        reactor.run()
     
     def start_ssl(self):
-        log.info("%s %s.", _("Starting server in PID"), os.getpid())
-        reactor.listenSSL(self.port, self.site, ServerContextFactory())
+        self.socket = reactor.listenSSL(self.port, self.site, 
ServerContextFactory())
         log.info("serving on %s:%s view at https://127.0.0.1:%s";, "0.0.0.0",
             self.port, self.port)
-        self.plugins.enable_plugins()
-        reactor.run()
-
-    def shutdown(self, *args):
+    
+    def stop(self):
         log.info("Shutting down webserver")
         self.plugins.disable_plugins()
         log.debug("Saving configuration file")
-        self.config.save()
+        self.config.save()
+        self.socket.stopListening()
+        self.socket = None
+
+    def shutdown(self, *args):
+        self.stop()
         try:
             reactor.stop()
         except error.ReactorNotRunning:

Modified: trunk/deluge/ui/web/web.py
===================================================================
--- trunk/deluge/ui/web/web.py  2009-08-03 14:40:24 UTC (rev 5610)
+++ trunk/deluge/ui/web/web.py  2009-08-03 15:40:58 UTC (rev 5611)
@@ -59,6 +59,8 @@
         except:
             pass
         else:
+            group.add_option("--no-ssl", dest="ssl", action="store_false",
+                    help="Forces the webserver to disable ssl", default=False)
             group.add_option("--ssl", dest="ssl", action="store_true",
                     help="Forces the webserver to use ssl", default=False)
         self.parser.add_option_group(group)
@@ -76,12 +78,12 @@
         if self.options.port:
             self.server.port = self.options.port
         
-        if self.options.ssl or self.server.https:
+        if self.options.ssl:
             self.server.https = self.options.ssl
-            self.server.start_ssl()
-        else:
-            self.server.start()
 
+        self.server.install_signal_handlers()
+        self.server.start()
+
 def start():
     web = Web()
     web.start()
\ No newline at end of file



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to