mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-02-04 08:13:38 +00:00
web_server: Move shutdown handling to main
This will keep web server de-coupled with service that want to shutdown on exit. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
adb08df512
commit
94255806cf
@ -126,6 +126,11 @@ def adapt_config(arguments):
|
||||
setattr(cfg, argument_name, argument_value)
|
||||
|
||||
|
||||
def on_web_server_stop():
|
||||
"""Stop all other threads since web server is trying to exit."""
|
||||
setup.stop()
|
||||
|
||||
|
||||
def main():
|
||||
"""Intialize and start the application"""
|
||||
arguments = parse_arguments()
|
||||
@ -173,7 +178,7 @@ def main():
|
||||
setup.run_setup_in_background()
|
||||
|
||||
web_server.init()
|
||||
web_server.run()
|
||||
web_server.run(on_web_server_stop)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@ -23,7 +23,7 @@ import os
|
||||
|
||||
import cherrypy
|
||||
|
||||
from . import cfg, log, module_loader, setup, web_framework
|
||||
from . import cfg, log, module_loader, web_framework
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -89,13 +89,8 @@ def init():
|
||||
cherrypy.engine.signal_handler.subscribe()
|
||||
|
||||
|
||||
def on_server_stop():
|
||||
"""Stop all other threads since web server is trying to exit."""
|
||||
setup.stop()
|
||||
|
||||
|
||||
def run():
|
||||
def run(on_web_server_stop):
|
||||
"""Start the web server and block it until exit."""
|
||||
cherrypy.engine.start()
|
||||
cherrypy.engine.subscribe('stop', on_server_stop)
|
||||
cherrypy.engine.subscribe('stop', on_web_server_stop)
|
||||
cherrypy.engine.block()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user