From 395ca8b75c9a772c67f61183316db9032d67c5b3 Mon Sep 17 00:00:00 2001 From: Michael Chen Date: Thu, 23 Oct 2014 01:06:38 -0700 Subject: [PATCH] Add sigterm handler to shutdown from rc.d scripts --- Mylar.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Mylar.py b/Mylar.py index 28668c47..da385146 100644 --- a/Mylar.py +++ b/Mylar.py @@ -17,6 +17,7 @@ import os, sys, locale import time import threading +import signal from lib.configobj import ConfigObj @@ -28,7 +29,9 @@ try: import argparse except ImportError: import lib.argparse as argparse - + +def handler_sigterm(signum, frame): + mylar.SIGNAL = 'shutdown' def main(): @@ -173,6 +176,8 @@ def main(): # Start the background threads mylar.start() + + signal.signal(signal.SIGTERM, handler_sigterm) while True: if not mylar.SIGNAL: