1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-11-24 09:18:08 +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 language: python
python: python:
- "2.7"
- "3.3" - "3.3"
- "3.4"
install: install:
- "pip install -r requirements.txt --use-mirrors" - "pip install -r requirements.txt --use-mirrors"

View File

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

View File

@ -160,7 +160,7 @@ class Server(object):
except OSError as e: except OSError as e:
if e.errno == errno.EADDRINUSE: # socket already in use if e.errno == errno.EADDRINUSE: # socket already in use
logging.critical("socket in use for {}:{}".format(self._host, self._port)) logging.critical("socket in use for {}:{}".format(self._host, self._port))
self._cleanup() self._cleanup(graceful=False)
ioloop = tornado.ioloop.IOLoop.instance() ioloop = tornado.ioloop.IOLoop.instance()
self._stream = zmqstream.ZMQStream(router, ioloop) self._stream = zmqstream.ZMQStream(router, ioloop)
@ -201,7 +201,7 @@ class Server(object):
self._router.bind("ipc:///tmp/gns3.ipc") self._router.bind("ipc:///tmp/gns3.ipc")
except zmq.error.ZMQError as e: except zmq.error.ZMQError as e:
log.critical("Could not start ZeroMQ server on ipc:///tmp/gns3.ipc, reason: {}".format(e)) log.critical("Could not start ZeroMQ server on ipc:///tmp/gns3.ipc, reason: {}".format(e))
self._cleanup() self._cleanup(graceful=False)
raise SystemExit raise SystemExit
log.info("ZeroMQ server listening to ipc:///tmp/gns3.ipc") log.info("ZeroMQ server listening to ipc:///tmp/gns3.ipc")
else: else:
@ -209,7 +209,7 @@ class Server(object):
self._router.bind("tcp://127.0.0.1:{}".format(self._zmq_port)) self._router.bind("tcp://127.0.0.1:{}".format(self._zmq_port))
except zmq.error.ZMQError as e: except zmq.error.ZMQError as e:
log.critical("Could not start ZeroMQ server on 127.0.0.1:{}, reason: {}".format(self._zmq_port, 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 raise SystemExit
log.info("ZeroMQ server listening to 127.0.0.1:{}".format(self._zmq_port)) log.info("ZeroMQ server listening to 127.0.0.1:{}".format(self._zmq_port))
return self._router return self._router
@ -251,25 +251,26 @@ class Server(object):
ioloop = tornado.ioloop.IOLoop.instance() ioloop = tornado.ioloop.IOLoop.instance()
ioloop.stop() ioloop.stop()
def _cleanup(self, signum=None): def _cleanup(self, signum=None, graceful=True):
""" """
Shutdowns any running module processes Shutdowns any running module processes
and adds a callback to stop the event loop & ZeroMQ and adds a callback to stop the event loop & ZeroMQ
:param signum: signal number (if called by a signal handler) :param signum: signal number (if called by a signal handler)
:param graceful: gracefully stop the modules
""" """
# terminate all modules # terminate all modules
for module in self._modules: for module in self._modules:
if module.is_alive(): if module.is_alive() and graceful:
log.info("stopping {}".format(module.name)) log.info("stopping {}".format(module.name))
self.stop_module(module.name) self.stop_module(module.name)
module.join(timeout=3) module.join(timeout=3)
if module.is_alive(): if module.is_alive():
# just kill the module if it is still alive. # just kill the module if it is still alive.
log.info("terminating {}".format(module.name)) log.info("terminating {}".format(module.name))
module.terminate() module.terminate()
module.join(timeout=1) module.join(timeout=1)
ioloop = tornado.ioloop.IOLoop.instance() ioloop = tornado.ioloop.IOLoop.instance()
if signum: if signum: