Improve shutdown cleanliness under uWSGI.

This commit is contained in:
Nate Coraor
2017-11-17 13:52:24 -05:00
parent c18521d7f7
commit 1ec960bcf6
6 changed files with 34 additions and 13 deletions
+13
View File
@@ -42,6 +42,11 @@ try:
except ImportError:
Daemonize = None
try:
import uwsgi
except:
uwsgi = None
REQUIRES_DAEMONIZE_MESSAGE = "Attempted to use Galaxy in daemon mode, but daemonize is unavailable."
log = logging.getLogger(__name__)
@@ -58,6 +63,8 @@ DEFAULT_VERBOSE = True
DESCRIPTION = "Daemonized entry point for Galaxy."
SHUTDOWN_MSG = '__SHUTDOWN__'
UWSGI_FARM_VAR = '_GALAXY_UWSGI_FARM_NAME'
exit = threading.Event()
@@ -96,6 +103,12 @@ def load_galaxy_app(
def handle_signal(signum, frame):
log.info('Received signal %d, exiting', signum)
if uwsgi and 'mule_id' in dir(uwsgi) and uwsgi.mule_id() > 0:
farm = os.environ.get(UWSGI_FARM_VAR, None)
if farm:
uwsgi.farm_msg(farm, SHUTDOWN_MSG)
else:
uwsgi.mule_msg(SHUTDOWN_MSG, uwsgi.mule_id())
exit.set()
+3 -1
View File
@@ -22,7 +22,7 @@ ALIASES = {
'http': ('httprouter', 'socket', 'uwsgi-socket', 'suwsgi-socket', 'ssl-socket'),
}
DEFAULT_ARGS = {
'_all_': ('virtualenv', 'pythonpath', 'master', 'threads', 'http', 'static-map', 'die-on-term', 'enable-threads'),
'_all_': ('virtualenv', 'pythonpath', 'master', 'threads', 'http', 'static-map', 'die-on-term', 'hook-master-start', 'enable-threads'),
'galaxy': ('py-call-osafterfork', 'mule', 'farm'),
'reports': (),
'tool_shed': (),
@@ -97,6 +97,8 @@ def _get_uwsgi_args(cliargs, kwargs):
'/static={here}/static'.format(here=os.getcwd())),
'die-on-term': True,
'enable-threads': True,
'hook-master-start': ('unix_signal:2 gracefully_kill_them_all',
'unix_signal:15 gracefully_kill_them_all'),
'py-call-osafterfork': True,
'mule': ('=lib/galaxy/main.py',) * handlerct,
'farm': '={name}:{mules}'.format(