Skip to content

Commit

Permalink
Builtin destination to shutdown the server.
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj committed Apr 1, 2014
1 parent ab02925 commit a92da02
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gns3server/handlers/jsonrpc_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ def on_message(self, message):
# This is a notification, silently ignore this error...
return

if method.startswith("builtin"):
log.info("calling built-in method {}".format(method))
self.destinations[method]()
return

module = self.destinations[method]
# ZMQ requests are encoded in JSON
# format is a JSON array: [session ID, JSON-RPC request]
Expand Down
2 changes: 2 additions & 0 deletions gns3server/modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ def signal_handler(signum=None, frame=None):
signals = [signal.SIGTERM, signal.SIGINT]
if not sys.platform.startswith("win"):
signals.extend([signal.SIGHUP, signal.SIGQUIT])
else:
signals.extend([signal.SIGBREAK])
for sig in signals:
signal.signal(sig, signal_handler)

Expand Down
2 changes: 2 additions & 0 deletions gns3server/modules/dynamips/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ def stop(self):
Properly stops the module.
"""

#if not sys.platform.startswith("win32"):
# self._callback.stop()
if self._hypervisor_manager:
self._hypervisor_manager.stop_all_hypervisors()
IModule.stop(self) # this will stop the I/O loop
Expand Down
1 change: 1 addition & 0 deletions gns3server/modules/iou/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def stop(self):
Properly stops the module.
"""

#self._iou_callback.stop()
# delete all IOU instances
for iou_id in self._iou_instances:
iou_instance = self._iou_instances[iou_id]
Expand Down
5 changes: 5 additions & 0 deletions gns3server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def load_modules(self):
# instance.start() # starts the new process
#=======================================================================

# special built-in destination to stop the server
JSONRPCWebSocket.register_destination("builtin.stop", self._cleanup)

for module in MODULES:
instance = module(module.__name__.lower(),
"127.0.0.1", # ZeroMQ server address
Expand Down Expand Up @@ -151,6 +154,8 @@ def signal_handler(signum=None, frame=None):
signals = [signal.SIGTERM, signal.SIGINT]
if not sys.platform.startswith("win"):
signals.extend([signal.SIGHUP, signal.SIGQUIT])
else:
signals.extend([signal.SIGBREAK])
for sig in signals:
signal.signal(sig, signal_handler)

Expand Down

0 comments on commit a92da02

Please sign in to comment.