Commit f3559fa1 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[1451] apply patch one

with a few amendments, see ticket comment
parent ea85f834
...@@ -98,20 +98,32 @@ class DDNSServer: ...@@ -98,20 +98,32 @@ class DDNSServer:
''' '''
if cmd == "shutdown": if cmd == "shutdown":
logger.info(DDNS_RECEIVED_SHUTDOWN_COMMAND) logger.info(DDNS_RECEIVED_SHUTDOWN_COMMAND)
self.shutdown() self.trigger_shutdown()
answer = create_answer(0) answer = create_answer(0)
else: else:
answer = create_answer(1, "Unknown command: " + str(cmd)) answer = create_answer(1, "Unknown command: " + str(cmd))
return answer return answer
def shutdown(self): def trigger_shutdown(self):
''' '''Initiate a shutdown sequence.
Shut down the server. Perform any cleanup that is necessary.
Currently, this only sets the internal _shutdown value to true, This method is expected to be called in various ways including
so the main loop in run() stops. in the middle of a signal handler, and is designed to be as simple
as possible to minimize side effects. Actual shutdown will take
place in a normal control flow.
''' '''
self._shutdown = True
logger.info(DDNS_SHUTDOWN) logger.info(DDNS_SHUTDOWN)
self._shutdown = True
def shutdown_cleanup(self):
'''
Perform any cleanup that is necessary when shutting down the server.
Do NOT call this to initialize shutdown, use trigger_shutdown().
Currently, it does nothing, but cleanup routines are expected.
'''
pass
def run(self): def run(self):
''' '''
...@@ -126,6 +138,7 @@ class DDNSServer: ...@@ -126,6 +138,7 @@ class DDNSServer:
# make such a distinction easily, but once we do, this would # make such a distinction easily, but once we do, this would
# be the place to catch. # be the place to catch.
self._cc.check_command(False) self._cc.check_command(False)
self.shutdown_cleanup()
logger.info(DDNS_STOPPED) logger.info(DDNS_STOPPED)
def create_signal_handler(ddns_server): def create_signal_handler(ddns_server):
...@@ -140,7 +153,7 @@ def create_signal_handler(ddns_server): ...@@ -140,7 +153,7 @@ def create_signal_handler(ddns_server):
here, the actual signal is not checked and the server is simply shut here, the actual signal is not checked and the server is simply shut
down. down.
''' '''
ddns_server.shutdown() ddns_server.trigger_shutdown()
return signal_handler return signal_handler
def set_signal_handler(signal_handler): def set_signal_handler(signal_handler):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment