diff --git a/SAS/LSMR/src/manage.py b/SAS/LSMR/src/manage.py index 5bc33ce0e8cb761f8ee73afee24381f48450e220..aef23caff026672979a7bbf2271b1a835bdc2d18 100755 --- a/SAS/LSMR/src/manage.py +++ b/SAS/LSMR/src/manage.py @@ -1,9 +1,28 @@ #!/usr/bin/env python3 import os import sys +import signal + +def subscribe_to_signals(): + # raise SignalException when a signal is caught so django will exit gracefully + class SignalException(Exception): + pass + + def signal_handler(_s, _f): + raise SignalException("signal %s received..." % (_s,)) + + for s in [signal.SIGHUP, signal.SIGINT]: + signal.signal(s, signal_handler) + if __name__ == "__main__": + # do subscribe to more signals than django does for proper exits during testing + if os.environ.get('LSMR_RAISE_ON_SIGNALS', "False").lower() in ["true", "1", "on"]: + subscribe_to_signals() + + # normal django startup. Specify the DJANGO_SETTINGS_MODULE, and run it. os.environ.setdefault("DJANGO_SETTINGS_MODULE", "lsmr.settings") + try: from django.core.management import execute_from_command_line except ImportError as exc: diff --git a/SAS/LSMR/test/t_lsmrapp_scheduling_functional.run b/SAS/LSMR/test/t_lsmrapp_scheduling_functional.run index 8777ac110a379ada9af742134c2ece59a8387810..fe3d426967aec923b5336d75db9e416262112516 100755 --- a/SAS/LSMR/test/t_lsmrapp_scheduling_functional.run +++ b/SAS/LSMR/test/t_lsmrapp_scheduling_functional.run @@ -56,6 +56,7 @@ sleep 5 echo "Started Django test database server\n\n" # Run Django test instance +export LSMR_RAISE_ON_SIGNALS="True" DJANGO_TEST_PORT=8777 lsmr -p $DJANGO_TEST_PORT -C $DJANGO_TEST_DATABASE_NAME & PIDS="$! $PIDS" diff --git a/SAS/LSMR/test/t_lsmrapp_specification_functional.run b/SAS/LSMR/test/t_lsmrapp_specification_functional.run index a3895786e8a8818abd89357a2750fa2bdb059035..9983333a5e1313cbaa8de6810b14bef1477f5711 100755 --- a/SAS/LSMR/test/t_lsmrapp_specification_functional.run +++ b/SAS/LSMR/test/t_lsmrapp_specification_functional.run @@ -56,6 +56,7 @@ sleep 5 echo "Started Django test database server\n\n" # Run Django test instance +export LSMR_RAISE_ON_SIGNALS="True" DJANGO_TEST_PORT=8777 lsmr -p $DJANGO_TEST_PORT -C $DJANGO_TEST_DATABASE_NAME & PIDS="$! $PIDS"