Skip to content

Commit 8590003

Browse files
committed
Gracefully shutdown in response to SIGTERM
Fixes duosecurity#6
1 parent ed6c6b0 commit 8590003

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Diff for: duologsync/app.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ def main():
4747
args = arg_parser.parse_args()
4848

4949
# Handle shutting down the program via Ctrl-C
50-
signal.signal(signal.SIGINT, sigint_handler)
50+
signal.signal(signal.SIGINT, signal_handler)
51+
# Handle shutting down the program via SIGTERM
52+
signal.signal(signal.SIGTERM, signal_handler)
5153

5254
# Create a config Dictionary from a YAML file located at args.ConfigPath
5355
config = Config.create_config(args.ConfigPath)
@@ -82,16 +84,20 @@ def main():
8284
print(f"DuoLogSync: shutdown successfully. Check "
8385
f"{Config.get_log_filepath()} for program logs")
8486

85-
def sigint_handler(signal_number, stack_frame):
87+
def signal_handler(signal_number, stack_frame):
8688
"""
87-
Handler for SIGINT (Ctrl-C) to gracefully shutdown DuoLogSync
89+
Handler for signals to gracefully shutdown DuoLogSync
8890
"""
8991

90-
shutdown_reason = f"received signal {signal_number} (Ctrl-C)"
92+
if signal_number == signal.SIGINT:
93+
shutdown_reason = f"received signal {signal_number} (Ctrl-C)"
94+
else:
95+
shutdown_reason = f"received signal {signal.strsignal(signal_number)}"
96+
9197
Program.initiate_shutdown(shutdown_reason)
9298

9399
if stack_frame:
94-
Program.log(f"DuoLogSync: stack frame from Ctrl-C is {stack_frame}",
100+
Program.log(f"DuoLogSync: stack frame from signal is {stack_frame}",
95101
logging.INFO)
96102

97103
def create_tasks(server_to_writer):

0 commit comments

Comments
 (0)