Skip to content

Commit

Permalink
Update the way we start controller to avoid hiding crash reports
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-duponchelle committed Dec 5, 2016
1 parent cb02046 commit 9a632fb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
15 changes: 12 additions & 3 deletions gns3server/web/web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def instance(host=None, port=None):

def _run_application(self, handler, ssl_context=None):
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:
log.critical("Could not start the server: {}".format(e))
return False
Expand Down Expand Up @@ -249,6 +250,13 @@ class in_pktinfo(ctypes.Structure):
time.sleep(1) # this is to prevent too many request to slow down the server
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):
"""
Starts the server.
Expand Down Expand Up @@ -284,6 +292,9 @@ def wakeup():
log.debug("ENV %s=%s", key, val)

self._app = aiohttp.web.Application()
# Background task started with the server
self._app.on_startup.append(self._on_startup)

# Allow CORS for this domains
cors = aiohttp_cors.setup(self._app, defaults={
# Default web server for web gui dev
Expand Down Expand Up @@ -311,8 +322,6 @@ def wakeup():
self._signal_handling()
self._exit_handling()

controller_start = asyncio.async(Controller.instance().start())

if server_config.getboolean("shell"):
asyncio.async(self.start_shell())

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
jsonschema>=2.4.0
aiohttp>=1.1.3
aiohttp>=1.1.6
aiohttp_cors>=0.4.0
yarl>=0.7.0
Jinja2>=2.7.3
Expand Down

0 comments on commit 9a632fb

Please sign in to comment.