mirror of
https://github.com/GNS3/gns3-server.git
synced 2024-11-16 16:54:51 +02:00
Catch SIGTERM, SIGINT, SIGHUP and SIGQUIT to properly shutdown the
server.
This commit is contained in:
parent
2f23a092e3
commit
798f0367b9
@ -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()
|
||||
|
@ -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):
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user