|
|
|
@ -352,6 +352,19 @@ class Worker(object):
|
|
|
|
|
signal.signal(signal.SIGINT, self.request_stop)
|
|
|
|
|
signal.signal(signal.SIGTERM, self.request_stop)
|
|
|
|
|
|
|
|
|
|
def kill_horse(self):
|
|
|
|
|
"""
|
|
|
|
|
Kill the horse but catch "No such process" error has the horse could already be dead.
|
|
|
|
|
"""
|
|
|
|
|
try:
|
|
|
|
|
os.kill(self.horse_pid, signal.SIGKILL)
|
|
|
|
|
except OSError as e:
|
|
|
|
|
if e.errno == errno.ESRCH:
|
|
|
|
|
# "No such process" is fine with us
|
|
|
|
|
self.log.debug('Horse already dead')
|
|
|
|
|
else:
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
def request_force_stop(self, signum, frame):
|
|
|
|
|
"""Terminates the application (cold shutdown).
|
|
|
|
|
"""
|
|
|
|
@ -361,13 +374,7 @@ class Worker(object):
|
|
|
|
|
if self.horse_pid:
|
|
|
|
|
msg = 'Taking down horse {0} with me'.format(self.horse_pid)
|
|
|
|
|
self.log.debug(msg)
|
|
|
|
|
try:
|
|
|
|
|
os.kill(self.horse_pid, signal.SIGKILL)
|
|
|
|
|
except OSError as e:
|
|
|
|
|
# ESRCH ("No such process") is fine with us
|
|
|
|
|
if e.errno != errno.ESRCH:
|
|
|
|
|
self.log.debug('Horse already down')
|
|
|
|
|
raise
|
|
|
|
|
self.kill_horse()
|
|
|
|
|
raise SystemExit()
|
|
|
|
|
|
|
|
|
|
def request_stop(self, signum, frame):
|
|
|
|
@ -834,7 +841,7 @@ class HerokuWorker(Worker):
|
|
|
|
|
"""If horse is alive send it SIGRTMIN"""
|
|
|
|
|
if self.horse_pid != 0:
|
|
|
|
|
self.log.warning('Warm shut down requested, sending horse SIGRTMIN signal')
|
|
|
|
|
os.kill(self.horse_pid, signal.SIGRTMIN)
|
|
|
|
|
self.kill_horse()
|
|
|
|
|
else:
|
|
|
|
|
self.log.warning('Warm shut down requested, no horse found')
|
|
|
|
|
|
|
|
|
|