diff --git a/docs/source/settings.rst b/docs/source/settings.rst index 476355c1..c5ac6c3d 100644 --- a/docs/source/settings.rst +++ b/docs/source/settings.rst @@ -782,6 +782,17 @@ two integers of number of workers after and before change. If the number of workers is set for the first time, old_value would be None. +on_exit +~~~~~~~ +* :: + + def on_exit(): + pass + +Called just before exiting gunicorn. + +The callable needs to accept a single instance variable for the Arbiter. + Server Mechanics ---------------- diff --git a/gunicorn/arbiter.py b/gunicorn/arbiter.py index 6f4587af..3b4b05ab 100644 --- a/gunicorn/arbiter.py +++ b/gunicorn/arbiter.py @@ -296,6 +296,7 @@ class Arbiter(object): self.log.info("Reason: %s", reason) if self.pidfile is not None: self.pidfile.unlink() + self.cfg.on_exit(self) sys.exit(exit_status) def sleep(self): diff --git a/gunicorn/config.py b/gunicorn/config.py index 51125f2f..895049db 100644 --- a/gunicorn/config.py +++ b/gunicorn/config.py @@ -1422,6 +1422,21 @@ class NumWorkersChanged(Setting): None. """ +class OnExit(Setting): + name = "on_exit" + section = "Server Hooks" + validator = validate_callable(1) + + def on_exit(server): + pass + + default = staticmethod(on_exit) + desc = """\ + Called just before exiting gunicorn. + + The callable needs to accept a single instance variable for the Arbiter. + """ + class ProxyProtocol(Setting): name = "proxy_protocol"