Skip to content

Commit

Permalink
Improving the shutdown protocol for managers
Browse files Browse the repository at this point in the history
Shutting down a manager *process* was previously possible only through
signal handling, which correctly shut down the manager itself, and the
enclosing rest server that exposed it to the outside world. Now the
shutdown logic is managed entirely by the rest server, who shuts down
the manager and itself, and exposes this functionality via a REST API
call, giving the possibility to send requests for shutdown remotely. The
corresponding functionality has also been added to the REST client.

Yes, not ideal from the point of view of security, but we haven't put
attention to security at any point in time and this is no exception.

Signed-off-by: Rodrigo Tobar <rtobar@icrar.org>
  • Loading branch information
rtobar committed Jul 25, 2019
1 parent bea36b6 commit 1e561ef
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 3 additions & 0 deletions dlg/manager/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ def _request(self, url, method, content=None, headers={}):
url = '/api' + url
return RestClient._request(self, url, method, content=content, headers=headers)

def stop(self):
self._POST('/stop')

def cancelSession(self, sessionId):
self._POST('/sessions/%s/cancel' % urllib.quote(sessionId))

Expand Down
9 changes: 2 additions & 7 deletions dlg/manager/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,13 @@ def handle_signal(signNo, stack_frame):
_terminating = True
logger.info("Exiting from %s" % (dmName))

dm.shutdown()
server.stop()

server.stop_manager()
logger.info("Thanks for using our %s, come back again :-)" % (dmName))

signal.signal(signal.SIGINT, handle_signal)
signal.signal(signal.SIGTERM, handle_signal)

server_t = threading.Thread(target=server.start, args=(opts.host, opts.port), name="HTTP server")
server_t.start()
# Now simply wait...
signal.pause()
server.start(opts.host, opts.port)


def addCommonOptions(parser, defaultPort):
Expand Down
10 changes: 10 additions & 0 deletions dlg/manager/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import functools
import json
import logging
import threading

import bottle
import pkg_resources
Expand Down Expand Up @@ -113,6 +114,7 @@ def __init__(self, dm, maxreqsize=10):

# Mappings
app = self.app
app.post( '/api/stop', callback=self.stop_manager)
app.post( '/api/sessions', callback=self.createSession)
app.get( '/api/sessions', callback=self.getSessions)
app.get( '/api/sessions/<sessionId>', callback=self.getSessionInformation)
Expand All @@ -139,6 +141,14 @@ def initializeSpecifics(self, app):
The default implementation does nothing.
"""

def _stop_manager(self):
self.dm.shutdown()
self.stop()

@daliuge_aware
def stop_manager(self):
threading.Thread(target=self._stop_manager).start()

@daliuge_aware
def createSession(self):
newSession = bottle.request.json
Expand Down

0 comments on commit 1e561ef

Please sign in to comment.