From d0dc923d9201151b68e23c8b5210cb98a74b5ab1 Mon Sep 17 00:00:00 2001 From: Joshua Boniface Date: Mon, 25 Jun 2018 23:03:21 -0400 Subject: [PATCH] [#3] Add alternative shutdown functions to allow flushing on non-SIGHUP shutdowns --- pvcd.py | 23 ++++++++++++++++++++--- pvcd.service | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pvcd.py b/pvcd.py index 25684dc3..9caad55b 100755 --- a/pvcd.py +++ b/pvcd.py @@ -153,10 +153,27 @@ def cleanup(signum, frame): # Exit sys.exit(0) +# Flush function +def flush(): + this_node = t_node[myhostname] + this_node.flush() + +# Shutdown function +def dshutdown(): + ansiiprint.echo('Flushing this node', '', 'e') + flush() + ansiiprint.echo('NOTE: This node must be unflushed by the administrator after daemon startup', '', 'i') + cleanup() + +# Reload shutdown function +def dreload(): + cleanup() + # Handle signals gracefully -signal.signal(signal.SIGTERM, cleanup) -signal.signal(signal.SIGINT, cleanup) -signal.signal(signal.SIGQUIT, cleanup) +signal.signal(signal.SIGTERM, dshutdown) +signal.signal(signal.SIGINT, dshutdown) +signal.signal(signal.SIGQUIT, dshutdown) +signal.signal(signal.SIGHUP, dreload) # Gather useful data about our host for staticdata # Static data format: 'cpu_count', 'arch', 'os', 'kernel' diff --git a/pvcd.service b/pvcd.service index ffe834f3..ef36e8cc 100644 --- a/pvcd.service +++ b/pvcd.service @@ -9,6 +9,7 @@ WorkingDirectory = /usr/share/pvc Environment = PYTHONUNBUFFERED=true Environment = PVCD_CONFIG_FILE=/etc/pvc/pvcd.conf ExecStart = /usr/share/pvc/pvcd.py +ExecReload = /bin/kill -HUP $MAINPID Restart = on-failure [Install]