mirror of
https://git.deluge-torrent.org/deluge
synced 2025-04-20 03:24:54 +00:00
change it so starting in ssl mode is left up to the server
add a stop method that doesn't stop the reactor
This commit is contained in:
parent
a14f4f6869
commit
1f817b3d56
2 changed files with 44 additions and 31 deletions
|
@ -435,6 +435,7 @@ class DelugeWeb(component.Component):
|
|||
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 @@ class DelugeWeb(component.Component):
|
|||
self.web_api = WebApi()
|
||||
self.auth = Auth()
|
||||
|
||||
# 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
|
||||
SetConsoleCtrlHandler(win_handler)
|
||||
|
||||
# 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
|
||||
SetConsoleCtrlHandler(win_handler)
|
||||
|
||||
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:
|
||||
|
|
|
@ -59,6 +59,8 @@ class Web(_UI):
|
|||
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,11 +78,11 @@ class Web(_UI):
|
|||
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()
|
||||
|
|
Loading…
Add table
Reference in a new issue