diff --git a/changedetection.py b/changedetection.py index b6249538..03914c1d 100755 --- a/changedetection.py +++ b/changedetection.py @@ -7,9 +7,17 @@ from changedetectionio import changedetection import multiprocessing +import signal -if __name__ == '__main__': +def sigterm_handler(_signo, _stack_frame): + print('Shutdown: Got SIGCHLD') + print('Process: %d interupted %s. Done editing' % (_signo, _stack_frame)) + + raise SystemExit + +if __name__ == '__main__': + signal.signal(signal.SIGCHLD, sigterm_handler) # The only way I could find to get Flask to shutdown, is to wrap it and then rely on the subsystem issuing SIGTERM/SIGKILL parse_process = multiprocessing.Process(target=changedetection.main) parse_process.daemon = True diff --git a/changedetectionio/changedetection.py b/changedetectionio/changedetection.py index b6119f0d..6d07dfc8 100755 --- a/changedetectionio/changedetection.py +++ b/changedetectionio/changedetection.py @@ -88,6 +88,7 @@ def main(): "Or use the -C parameter to create the directory.".format(app_config['datastore_path']), file=sys.stderr) sys.exit(2) + datastore = store.ChangeDetectionStore(datastore_path=app_config['datastore_path'], version_tag=__version__) app = changedetection_app(app_config, datastore) signal.signal(signal.SIGTERM, sigterm_handler)