mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Exit with a non-zero status if workers don't boot.
Raising a HaltServer exception in the arbiter will now exit with the provided reason and status code.
This commit is contained in:
parent
43232411fc
commit
63b53c9f51
5
examples/boot_fail.py
Normal file
5
examples/boot_fail.py
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
raise RuntimeError("Bad app!")
|
||||
|
||||
def app(environ, start_response):
|
||||
assert 1 == 2, "Shouldn't get here."
|
||||
@ -14,6 +14,7 @@ import sys
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from gunicorn.errors import HaltServer
|
||||
from gunicorn.pidfile import Pidfile
|
||||
from gunicorn.sock import create_socket
|
||||
from gunicorn import util
|
||||
@ -168,6 +169,8 @@ class Arbiter(object):
|
||||
self.halt()
|
||||
except KeyboardInterrupt:
|
||||
self.halt()
|
||||
except HaltServer, inst:
|
||||
self.halt(reason=inst.reason, exit_status=inst.exit_status)
|
||||
except SystemExit:
|
||||
raise
|
||||
except Exception:
|
||||
@ -259,13 +262,15 @@ class Arbiter(object):
|
||||
if e.errno not in [errno.EAGAIN, errno.EINTR]:
|
||||
raise
|
||||
|
||||
def halt(self):
|
||||
def halt(self, reason=None, exit_status=0):
|
||||
""" halt arbiter """
|
||||
self.stop()
|
||||
self.log.info("Shutting down: %s" % self.master_name)
|
||||
if reason is not None:
|
||||
self.log.info("Reason: %s" % reason)
|
||||
if self.pidfile is not None:
|
||||
self.pidfile.unlink()
|
||||
sys.exit(0)
|
||||
sys.exit(exit_status)
|
||||
|
||||
def sleep(self):
|
||||
"""\
|
||||
@ -386,7 +391,8 @@ class Arbiter(object):
|
||||
# to avoid infinite start/stop cycles.
|
||||
exitcode = status >> 8
|
||||
if exitcode == self.WORKER_BOOT_ERROR:
|
||||
raise StopIteration
|
||||
reason = "Worker failed to boot."
|
||||
raise HaltServer(reason, self.WORKER_BOOT_ERROR)
|
||||
worker = self.WORKERS.pop(wpid, None)
|
||||
if not worker:
|
||||
continue
|
||||
|
||||
8
gunicorn/errors.py
Normal file
8
gunicorn/errors.py
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
class HaltServer(Exception):
|
||||
def __init__(self, reason, exit_status=1):
|
||||
self.reason = reason
|
||||
self.exit_status = exit_status
|
||||
|
||||
def __str__(self):
|
||||
return "<HaltServer %r %d>" % (self.reason, self.exit_status)
|
||||
Loading…
x
Reference in New Issue
Block a user