mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-02 22:48:40 +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)
|
os.rename(old_config.config_file, backup_path)
|
||||||
del old_config
|
del old_config
|
||||||
|
|
||||||
|
self.socket = None
|
||||||
self.top_level = TopLevel()
|
self.top_level = TopLevel()
|
||||||
self.site = server.Site(self.top_level)
|
self.site = server.Site(self.top_level)
|
||||||
self.port = self.config["port"]
|
self.port = self.config["port"]
|
||||||
|
@ -444,47 +445,57 @@ class DelugeWeb(component.Component):
|
||||||
self.web_api = WebApi()
|
self.web_api = WebApi()
|
||||||
self.auth = Auth()
|
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
|
# Initalize the plugins
|
||||||
self.plugins = PluginManager()
|
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):
|
def start(self):
|
||||||
log.info("%s %s.", _("Starting server in PID"), os.getpid())
|
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",
|
log.info("serving on %s:%s view at http://127.0.0.1:%s", "0.0.0.0",
|
||||||
self.port, self.port)
|
self.port, self.port)
|
||||||
self.plugins.enable_plugins()
|
|
||||||
reactor.run()
|
|
||||||
|
|
||||||
def start_ssl(self):
|
def start_ssl(self):
|
||||||
log.info("%s %s.", _("Starting server in PID"), os.getpid())
|
self.socket = reactor.listenSSL(self.port, self.site, ServerContextFactory())
|
||||||
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",
|
log.info("serving on %s:%s view at https://127.0.0.1:%s", "0.0.0.0",
|
||||||
self.port, self.port)
|
self.port, self.port)
|
||||||
self.plugins.enable_plugins()
|
|
||||||
reactor.run()
|
def stop(self):
|
||||||
|
|
||||||
def shutdown(self, *args):
|
|
||||||
log.info("Shutting down webserver")
|
log.info("Shutting down webserver")
|
||||||
self.plugins.disable_plugins()
|
self.plugins.disable_plugins()
|
||||||
log.debug("Saving configuration file")
|
log.debug("Saving configuration file")
|
||||||
self.config.save()
|
self.config.save()
|
||||||
|
self.socket.stopListening()
|
||||||
|
self.socket = None
|
||||||
|
|
||||||
|
def shutdown(self, *args):
|
||||||
|
self.stop()
|
||||||
try:
|
try:
|
||||||
reactor.stop()
|
reactor.stop()
|
||||||
except error.ReactorNotRunning:
|
except error.ReactorNotRunning:
|
||||||
|
|
|
@ -59,6 +59,8 @@ class Web(_UI):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
else:
|
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",
|
group.add_option("--ssl", dest="ssl", action="store_true",
|
||||||
help="Forces the webserver to use ssl", default=False)
|
help="Forces the webserver to use ssl", default=False)
|
||||||
self.parser.add_option_group(group)
|
self.parser.add_option_group(group)
|
||||||
|
@ -76,11 +78,11 @@ class Web(_UI):
|
||||||
if self.options.port:
|
if self.options.port:
|
||||||
self.server.port = 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.https = self.options.ssl
|
||||||
self.server.start_ssl()
|
|
||||||
else:
|
self.server.install_signal_handlers()
|
||||||
self.server.start()
|
self.server.start()
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
web = Web()
|
web = Web()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue