summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2019-08-21 09:08:27 +0200
committerDaniil Baturin <daniil@baturin.org>2019-08-21 09:08:27 +0200
commita923efc0062119189d876e37514bd24b7773509e (patch)
treecd6a67f9a433673d804bbb6c5e5fc0cc0dc5ac86 /src
parent3cbebc67f970f1add6548c5e386b40d5632f8452 (diff)
downloadvyos-1x-a923efc0062119189d876e37514bd24b7773509e.tar.gz
vyos-1x-a923efc0062119189d876e37514bd24b7773509e.zip
T1598: clean up vyos-hostsd state dump on clean shutdown.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/services/vyos-hostsd9
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):