mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Tweak signal handling documentation
This commit is contained in:
parent
21ffa92be1
commit
55a01887a3
@ -1,8 +1,8 @@
|
|||||||
.. _signals:
|
.. _signals:
|
||||||
|
|
||||||
================
|
===============
|
||||||
Signal Handling
|
Signal Handling
|
||||||
================
|
===============
|
||||||
|
|
||||||
A brief description of the signals handled by Gunicorn. We also document the
|
A brief description of the signals handled by Gunicorn. We also document the
|
||||||
signals used internally by Gunicorn to communicate with the workers.
|
signals used internally by Gunicorn to communicate with the workers.
|
||||||
@ -10,20 +10,21 @@ signals used internally by Gunicorn to communicate with the workers.
|
|||||||
Master process
|
Master process
|
||||||
==============
|
==============
|
||||||
|
|
||||||
- **QUIT**, **INT**: Quick shutdown
|
- ``QUIT``, ``INT``: Quick shutdown
|
||||||
- **TERM**: Graceful shutdown. Waits for workers to finish their
|
- ``TERM``: Graceful shutdown. Waits for workers to finish their
|
||||||
current requests up to the *graceful timeout*.
|
current requests up to the :ref:`graceful-timeout`.
|
||||||
- **HUP**: Reload the configuration, start the new worker processes with a new
|
- ``HUP``: Reload the configuration, start the new worker processes with a new
|
||||||
configuration and gracefully shutdown older workers. If the application is
|
configuration and gracefully shutdown older workers. If the application is
|
||||||
not preloaded (using the ``--preload`` option), Gunicorn will also load the
|
not preloaded (using the :ref:`preload-app` option), Gunicorn will also load
|
||||||
new version.
|
the new version of it.
|
||||||
- **TTIN**: Increment the number of processes by one
|
- ``TTIN``: Increment the number of processes by one
|
||||||
- **TTOU**: Decrement the number of processes by one
|
- ``TTOU``: Decrement the number of processes by one
|
||||||
- **USR1**: Reopen the log files
|
- ``USR1``: Reopen the log files
|
||||||
- **USR2**: Upgrade the Gunicorn on the fly. A separate **TERM** signal should
|
- ``USR2``: Upgrade Gunicorn on the fly. A separate ``TERM`` signal should
|
||||||
be used to kill the old process. This signal can also be used to use the new
|
be used to kill the old master process. This signal can also be used to use
|
||||||
versions of pre-loaded applications.
|
the new versions of pre-loaded applications. See :ref:`binary-upgrade` for
|
||||||
- **WINCH**: Gracefully shutdown the worker processes when Gunicorn is
|
more information.
|
||||||
|
- ``WINCH``: Gracefully shutdown the worker processes when Gunicorn is
|
||||||
daemonized.
|
daemonized.
|
||||||
|
|
||||||
Worker process
|
Worker process
|
||||||
@ -33,9 +34,9 @@ Sending signals directly to the worker processes should not normally be
|
|||||||
needed. If the master process is running, any exited worker will be
|
needed. If the master process is running, any exited worker will be
|
||||||
automatically respawned.
|
automatically respawned.
|
||||||
|
|
||||||
- **QUIT**, **INT**: Quick shutdown
|
- ``QUIT``, ``INT``: Quick shutdown
|
||||||
- **TERM**: Graceful shutdown
|
- ``TERM``: Graceful shutdown
|
||||||
- **USR1**: Reopen the log files
|
- ``USR1``: Reopen the log files
|
||||||
|
|
||||||
Reload the configuration
|
Reload the configuration
|
||||||
========================
|
========================
|
||||||
@ -55,10 +56,12 @@ fly.
|
|||||||
2013-06-29 06:26:55 [20704] [INFO] Booting worker with pid: 20704
|
2013-06-29 06:26:55 [20704] [INFO] Booting worker with pid: 20704
|
||||||
|
|
||||||
|
|
||||||
Sending a **HUP** signal will reload the configuration, start the new
|
Sending a ``HUP`` signal will reload the configuration, start the new
|
||||||
worker processes with a new configuration and gracefully shutdown older
|
worker processes with a new configuration and gracefully shutdown older
|
||||||
workers. If the application is not preloaded (using the ``--preload``
|
workers. If the application is not preloaded (using the :ref:`preload-app`
|
||||||
option), Gunicorn will also load the new version.
|
option), Gunicorn will also load the new version of it.
|
||||||
|
|
||||||
|
.. _binary-upgrade:
|
||||||
|
|
||||||
Upgrading to a new binary on the fly
|
Upgrading to a new binary on the fly
|
||||||
====================================
|
====================================
|
||||||
@ -72,11 +75,10 @@ upgrading to a new version or adding/removing server modules), you can
|
|||||||
do it without any service downtime - no incoming requests will be
|
do it without any service downtime - no incoming requests will be
|
||||||
lost. Preloaded applications will also be reloaded.
|
lost. Preloaded applications will also be reloaded.
|
||||||
|
|
||||||
First, replace the old binary with a new one, then send the **USR2** signal to
|
First, replace the old binary with a new one, then send a ``USR2`` signal to
|
||||||
the master process. It executes a new binary whose .pid file is
|
the current master process. It executes a new binary whose PID file is
|
||||||
postfixed with .2 (e.g. /var/run/gunicorn.pid.2),
|
postfixed with ``.2`` (e.g. ``/var/run/gunicorn.pid.2``),
|
||||||
which in turn starts a new master process and the new worker processes::
|
which in turn starts a new master process and new worker processes::
|
||||||
|
|
||||||
|
|
||||||
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
||||||
20844 benoitc 20 0 54808 11m 3352 S 0.0 0.1 0:00.36 gunicorn: master [test:app]
|
20844 benoitc 20 0 54808 11m 3352 S 0.0 0.1 0:00.36 gunicorn: master [test:app]
|
||||||
@ -90,24 +92,24 @@ which in turn starts a new master process and the new worker processes::
|
|||||||
|
|
||||||
At this point, two instances of Gunicorn are running, handling the
|
At this point, two instances of Gunicorn are running, handling the
|
||||||
incoming requests together. To phase the old instance out, you have to
|
incoming requests together. To phase the old instance out, you have to
|
||||||
send the **WINCH** signal to the old master process, and its worker
|
send a ``WINCH`` signal to the old master process, and its worker
|
||||||
processes will start to gracefully shut down.
|
processes will start to gracefully shut down.
|
||||||
|
|
||||||
At this point you can still revert to the old server because it hasn't closed
|
At this point you can still revert to the old process since it hasn't closed
|
||||||
its listen sockets yet, by following these steps:
|
its listen sockets yet, by following these steps:
|
||||||
|
|
||||||
- Send the HUP signal to the old master process - it will start the worker
|
- Send a ``HUP`` signal to the old master process - it will start the worker
|
||||||
processes without reloading a configuration file
|
processes without reloading a configuration file
|
||||||
- Send the TERM signal to the new master process to gracefully shut down its
|
- Send a ``TERM`` signal to the new master process to gracefully shut down its
|
||||||
worker processes
|
worker processes
|
||||||
- Send the QUIT signal to the new master process to force it quit
|
- Send a ``QUIT`` signal to the new master process to force it quit
|
||||||
|
|
||||||
If for some reason the new worker processes do not quit, send the KILL signal
|
If for some reason the new worker processes do not quit, send a ``KILL`` signal
|
||||||
to them after the new master process quits, and everything is exactly as before
|
to them after the new master process quits, and everything will back to exactly
|
||||||
the upgrade attempt.
|
as before the upgrade attempt.
|
||||||
|
|
||||||
If an update is successful and you want to keep the new server, send
|
If the update is successful and you want to keep the new master process, send a
|
||||||
the TERM signal to the old master process to leave only the new server
|
``TERM`` signal to the old master process to leave only the new server
|
||||||
running::
|
running::
|
||||||
|
|
||||||
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user