mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 03:08:14 +00: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
|
Starts the event loop
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
log.info("{} module running with PID {}".format(self.name, self.pid))
|
||||||
self._setup()
|
self._setup()
|
||||||
try:
|
try:
|
||||||
self._ioloop.start()
|
self._ioloop.start()
|
||||||
|
@ -24,6 +24,7 @@ from zmq.eventloop import ioloop, zmqstream
|
|||||||
ioloop.install()
|
ioloop.install()
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import signal
|
||||||
import errno
|
import errno
|
||||||
import functools
|
import functools
|
||||||
import socket
|
import socket
|
||||||
@ -94,6 +95,13 @@ class Server(object):
|
|||||||
stream.on_recv(StompWebSocket.dispatch_message)
|
stream.on_recv(StompWebSocket.dispatch_message)
|
||||||
tornado.autoreload.add_reload_hook(functools.partial(self._cleanup, stop=False))
|
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:
|
try:
|
||||||
ioloop.start()
|
ioloop.start()
|
||||||
except (KeyboardInterrupt, SystemExit):
|
except (KeyboardInterrupt, SystemExit):
|
||||||
|
@ -15,5 +15,5 @@ def server(request):
|
|||||||
server_script = os.path.join(cwd, "../gns3server/main.py")
|
server_script = os.path.join(cwd, "../gns3server/main.py")
|
||||||
process = subprocess.Popen([sys.executable, server_script, "--port=8000"])
|
process = subprocess.Popen([sys.executable, server_script, "--port=8000"])
|
||||||
time.sleep(0.1) # give some time for the process to start
|
time.sleep(0.1) # give some time for the process to start
|
||||||
request.addfinalizer(process.kill)
|
request.addfinalizer(process.terminate)
|
||||||
return process
|
return process
|
||||||
|
Loading…
Reference in New Issue
Block a user