Handle SIGTERM

This commit is contained in:
luukas 2021-06-02 21:30:12 +03:00
parent 5a5cd65d4f
commit 344c2219ec

10
main.py
View File

@ -4,6 +4,7 @@ import json
import time
import argparse
import logging.config
import signal
""" Our custom classes / pip packages """
from app.classes.shared.console import console
@ -128,6 +129,15 @@ if __name__ == '__main__':
tasks_manager.start_main_kill_switch_watcher()
Crafty = MainPrompt(tasks_manager)
def sigterm_handler(signum, current_stack_frame):
print() # for newline
logger.info("Recieved SIGTERM, stopping Crafty")
console.info("Recieved SIGTERM, stopping Crafty")
Crafty.universal_exit()
signal.signal(signal.SIGTERM, sigterm_handler)
if not args.daemon:
try:
Crafty.cmdloop()