diff options
author | Daniil Baturin <daniil@baturin.org> | 2019-08-21 09:08:27 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2019-08-21 09:08:27 +0200 |
commit | a923efc0062119189d876e37514bd24b7773509e (patch) | |
tree | cd6a67f9a433673d804bbb6c5e5fc0cc0dc5ac86 /src | |
parent | 3cbebc67f970f1add6548c5e386b40d5632f8452 (diff) | |
download | vyos-1x-a923efc0062119189d876e37514bd24b7773509e.tar.gz vyos-1x-a923efc0062119189d876e37514bd24b7773509e.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): |