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

Fixes issue with server shutdown.

This commit is contained in:
grossmj 2014-05-14 11:24:14 -06:00
parent 9cc5131024
commit ff6c864294
3 changed files with 15 additions and 12 deletions

View File

@ -1,8 +1,8 @@
language: python
python:
- "2.7"
- "3.3"
- "3.4"
install:
- "pip install -r requirements.txt --use-mirrors"

View File

@ -302,6 +302,7 @@ class Dynamips(IModule):
else:
if "project_name" in request:
# for remote server
new_working_dir = os.path.join(self._projects_dir, request["project_name"])
if self._projects_dir != self._working_dir != new_working_dir:
@ -321,10 +322,11 @@ class Dynamips(IModule):
return
elif "working_dir" in request:
# for local server
new_working_dir = request.pop("working_dir")
self._hypervisor_manager.working_dir = new_working_dir
self._working_dir = new_working_dir
self._hypervisor_manager.working_dir = new_working_dir
# apply settings to the hypervisor manager
for name, value in request.items():

View File

@ -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,17 +251,18 @@ 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)