1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-28 11:18:11 +00:00

Update the way we start controller to avoid hiding crash reports

This commit is contained in:
Julien Duponchelle 2016-12-05 10:28:11 +01:00
parent cb02046e01
commit 9a632fb823
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 13 additions and 4 deletions

View File

@ -79,7 +79,8 @@ class WebServer:
def _run_application(self, handler, ssl_context=None): def _run_application(self, handler, ssl_context=None):
try: try:
self._server = self._loop.run_until_complete(self._loop.create_server(handler, self._host, self._port, ssl=ssl_context)) srv = self._loop.create_server(handler, self._host, self._port, ssl=ssl_context)
self._server, startup_res = self._loop.run_until_complete(asyncio.gather(srv, self._app.startup(), loop=self._loop))
except OSError as e: except OSError as e:
log.critical("Could not start the server: {}".format(e)) log.critical("Could not start the server: {}".format(e))
return False return False
@ -249,6 +250,13 @@ class WebServer:
time.sleep(1) # this is to prevent too many request to slow down the server time.sleep(1) # this is to prevent too many request to slow down the server
log.debug("UDP server discovery stopped") log.debug("UDP server discovery stopped")
@asyncio.coroutine
def _on_startup(self, *args):
"""
Called when the HTTP server start
"""
yield from Controller.instance().start()
def run(self): def run(self):
""" """
Starts the server. Starts the server.
@ -284,6 +292,9 @@ class WebServer:
log.debug("ENV %s=%s", key, val) log.debug("ENV %s=%s", key, val)
self._app = aiohttp.web.Application() self._app = aiohttp.web.Application()
# Background task started with the server
self._app.on_startup.append(self._on_startup)
# Allow CORS for this domains # Allow CORS for this domains
cors = aiohttp_cors.setup(self._app, defaults={ cors = aiohttp_cors.setup(self._app, defaults={
# Default web server for web gui dev # Default web server for web gui dev
@ -311,8 +322,6 @@ class WebServer:
self._signal_handling() self._signal_handling()
self._exit_handling() self._exit_handling()
controller_start = asyncio.async(Controller.instance().start())
if server_config.getboolean("shell"): if server_config.getboolean("shell"):
asyncio.async(self.start_shell()) asyncio.async(self.start_shell())

View File

@ -1,5 +1,5 @@
jsonschema>=2.4.0 jsonschema>=2.4.0
aiohttp>=1.1.3 aiohttp>=1.1.6
aiohttp_cors>=0.4.0 aiohttp_cors>=0.4.0
yarl>=0.7.0 yarl>=0.7.0
Jinja2>=2.7.3 Jinja2>=2.7.3