mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-04 06:21:15 +02:00
Fixes issue with server shutdown.
This commit is contained in:
1 parent
9cc5131024
commit
ff6c864294
3 files changed
+15
-12
No files matched your search
+11
-10
@@ -160,7 +160,7 @@ class Server(object):
|
||||
except OSError as e:
|
||||
if e.errno == errno.EADDRINUSE: # socket already in use
|
||||
logging.critical("socket in use for {}:{}".format(self._host, self._port))
|
||||
self._cleanup()
|
||||
self._cleanup(graceful=False)
|
||||
|
||||
ioloop = tornado.ioloop.IOLoop.instance()
|
||||
self._stream = zmqstream.ZMQStream(router, ioloop)
|
||||
@@ -201,7 +201,7 @@ class Server(object):
|
||||
self._router.bind("ipc:///tmp/gns3.ipc")
|
||||
except zmq.error.ZMQError as e:
|
||||
log.critical("Could not start ZeroMQ server on ipc:///tmp/gns3.ipc, reason: {}".format(e))
|
||||
self._cleanup()
|
||||
self._cleanup(graceful=False)
|
||||
raise SystemExit
|
||||
log.info("ZeroMQ server listening to ipc:///tmp/gns3.ipc")
|
||||
else:
|
||||
@@ -209,7 +209,7 @@ class Server(object):
|
||||
self._router.bind("tcp://127.0.0.1:{}".format(self._zmq_port))
|
||||
except zmq.error.ZMQError as e:
|
||||
log.critical("Could not start ZeroMQ server on 127.0.0.1:{}, reason: {}".format(self._zmq_port, e))
|
||||
self._cleanup()
|
||||
self._cleanup(graceful=False)
|
||||
raise SystemExit
|
||||
log.info("ZeroMQ server listening to 127.0.0.1:{}".format(self._zmq_port))
|
||||
return self._router
|
||||
@@ -251,25 +251,26 @@ class Server(object):
|
||||
ioloop = tornado.ioloop.IOLoop.instance()
|
||||
ioloop.stop()
|
||||
|
||||
def _cleanup(self, signum=None):
|
||||
def _cleanup(self, signum=None, graceful=True):
|
||||
"""
|
||||
Shutdowns any running module processes
|
||||
and adds a callback to stop the event loop & ZeroMQ
|
||||
|
||||
:param signum: signal number (if called by a signal handler)
|
||||
:param graceful: gracefully stop the modules
|
||||
"""
|
||||
|
||||
# terminate all modules
|
||||
for module in self._modules:
|
||||
if module.is_alive():
|
||||
if module.is_alive() and graceful:
|
||||
log.info("stopping {}".format(module.name))
|
||||
self.stop_module(module.name)
|
||||
module.join(timeout=3)
|
||||
if module.is_alive():
|
||||
# just kill the module if it is still alive.
|
||||
log.info("terminating {}".format(module.name))
|
||||
module.terminate()
|
||||
module.join(timeout=1)
|
||||
if module.is_alive():
|
||||
# just kill the module if it is still alive.
|
||||
log.info("terminating {}".format(module.name))
|
||||
module.terminate()
|
||||
module.join(timeout=1)
|
||||
|
||||
ioloop = tornado.ioloop.IOLoop.instance()
|
||||
if signum:
|
||||
|
||||
Reference in new issue
Block a user