diff options
author | Daniil Baturin <daniil@baturin.org> | 2019-08-21 09:08:27 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2019-08-27 08:15:15 +0200 |
commit | 21014e20bedb21fd4862120d0e338098284783f7 (patch) | |
tree | 5d345f7f4edd1728144ee0c47c2fe7ce29ff605b /src | |
parent | 8008fb508ec874ada5cb06866c1a0bd4c03be1e9 (diff) | |
download | vyos-1x-21014e20bedb21fd4862120d0e338098284783f7.tar.gz vyos-1x-21014e20bedb21fd4862120d0e338098284783f7.zip |
T1598: clean up vyos-hostsd state dump on clean shutdown.
Diffstat (limited to 'src')
-rwxr-xr-x | src/services/vyos-hostsd | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/services/vyos-hostsd b/src/services/vyos-hostsd index aec06c72c..1bcb2e1f5 100755 --- a/src/services/vyos-hostsd +++ b/src/services/vyos-hostsd @@ -20,6 +20,7 @@ import os import sys import time import json +import signal import traceback import zmq @@ -218,8 +219,16 @@ def handle_message(msg_json): with open(STATE_FILE, 'w') as f: json.dump(STATE, f) +def exit_handler(sig, frame): + """ Clean up the state when shutdown correctly """ + print("Cleaning up state") + os.unlink(STATE_FILE) + sys.exit(0) + if __name__ == '__main__': + signal.signal(signal.SIGTERM, exit_handler) + # Create a directory for state checkpoints os.makedirs(DATA_DIR, exist_ok=True) if os.path.exists(STATE_FILE): |