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

Catch SIGTERM, SIGINT, SIGHUP and SIGQUIT to properly shutdown the

server.
This commit is contained in:
grossmj 2013-12-06 17:52:16 -07:00
parent 2f23a092e3
commit 798f0367b9
3 changed files with 10 additions and 1 deletions

View File

@ -89,6 +89,7 @@ class IModule(multiprocessing.Process):
Starts the event loop
"""
log.info("{} module running with PID {}".format(self.name, self.pid))
self._setup()
try:
self._ioloop.start()

View File

@ -24,6 +24,7 @@ from zmq.eventloop import ioloop, zmqstream
ioloop.install()
import os
import signal
import errno
import functools
import socket
@ -94,6 +95,13 @@ class Server(object):
stream.on_recv(StompWebSocket.dispatch_message)
tornado.autoreload.add_reload_hook(functools.partial(self._cleanup, stop=False))
def signal_handler(signum=None, frame=None):
log.warning("Got signal {}, exiting...".format(signum))
self._cleanup()
for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]:
signal.signal(sig, signal_handler)
try:
ioloop.start()
except (KeyboardInterrupt, SystemExit):

View File

@ -15,5 +15,5 @@ def server(request):
server_script = os.path.join(cwd, "../gns3server/main.py")
process = subprocess.Popen([sys.executable, server_script, "--port=8000"])
time.sleep(0.1) # give some time for the process to start
request.addfinalizer(process.kill)
request.addfinalizer(process.terminate)
return process