Improve the "Running Gunicorn" command.

This commit is contained in:
Berker Peksag 2014-12-01 07:06:55 +02:00
parent 761a1e5b76
commit 2043779b23

View File

@ -2,6 +2,8 @@
Running Gunicorn Running Gunicorn
================ ================
.. highlight:: bash
You can run Gunicorn by using commands or integrate with Django or Paster. For You can run Gunicorn by using commands or integrate with Django or Paster. For
deploying Gunicorn in production see :doc:`deploy`. deploying Gunicorn in production see :doc:`deploy`.
@ -22,14 +24,9 @@ Where ``APP_MODULE`` is of the pattern ``$(MODULE_NAME):$(VARIABLE_NAME)``. The
module name can be a full dotted path. The variable name refers to a WSGI module name can be a full dotted path. The variable name refers to a WSGI
callable that should be found in the specified module. callable that should be found in the specified module.
Example with test app:: Example with the test app:
$ cd examples .. code-block:: python
$ cat test.py
# -*- coding: utf-8 -
#
# This file is part of gunicorn released under the MIT license.
# See the NOTICE for more information.
def app(environ, start_response): def app(environ, start_response):
"""Simplest possible application object""" """Simplest possible application object"""
@ -42,9 +39,35 @@ Example with test app::
start_response(status, response_headers) start_response(status, response_headers)
return iter([data]) return iter([data])
You can now run the app with the following command::
$ gunicorn --workers=2 test:app $ gunicorn --workers=2 test:app
Commonly Used Arguments
^^^^^^^^^^^^^^^^^^^^^^^
* ``-c CONFIG, --config=CONFIG`` - Specify the path to a config file or
Python module.
* ``-b BIND, --bind=BIND`` - Specify a server socket to bind. Server sockets
can be any of ``$(HOST)``, ``$(HOST):$(PORT)``, or ``unix:$(PATH)``.
An IP is a valid ``$(HOST)``.
* ``-w WORKERS, --workers=WORKERS`` - The number of worker processes. This
number should generally be between 2-4 workers per core in the server.
Check the :ref:`faq` for ideas on tuning this parameter.
* ``-k WORKERCLASS, --worker-class=WORKERCLASS`` - The type of worker process
to run. You'll definitely want to read the production page for the
implications of this parameter. You can set this to ``egg:gunicorn#$(NAME)``
where ``$(NAME)`` is one of ``sync``, ``eventlet``, ``gevent``, or
``tornado``, ``gthread``, ``gaiohttp``. ``sync`` is the default.
* ``-n APP_NAME, --name=APP_NAME`` - If setproctitle_ is installed you can
adjust the name of Gunicorn process as they appear in the process system
table (which affects tools like ``ps`` and ``top``).
See :ref:`configuration` and :ref:`settings` for detailed usage.
.. _setproctitle: http://pypi.python.org/pypi/setproctitle/
Integration Integration
=========== ===========
@ -54,13 +77,16 @@ Django
------ ------
Gunicorn will look for a WSGI callable named ``application`` if not specified. Gunicorn will look for a WSGI callable named ``application`` if not specified.
So for a typical Django project, invoking gunicorn would look like:: So for a typical Django project, invoking Gunicorn would look like::
gunicorn myproject.wsgi $ gunicorn myproject.wsgi
(This requires that your project be on the Python path; the simplest way
to ensure that is to run this command from the same directory as your .. note::
manage.py file.)
This requires that your project be on the Python path; the simplest way to
ensure that is to run this command from the same directory as your
``manage.py`` file.
You can use the You can use the
`--env <http://docs.gunicorn.org/en/latest/settings.html#raw-env>`_ option `--env <http://docs.gunicorn.org/en/latest/settings.html#raw-env>`_ option
@ -69,23 +95,22 @@ add your application path to ``PYTHONPATH`` using the
`--pythonpath <http://docs.gunicorn.org/en/latest/settings.html#pythonpath>`_ `--pythonpath <http://docs.gunicorn.org/en/latest/settings.html#pythonpath>`_
option:: option::
gunicorn --env DJANGO_SETTINGS_MODULE=myproject.settings myproject.wsgi $ gunicorn --env DJANGO_SETTINGS_MODULE=myproject.settings myproject.wsgi
Paste Paste
----- -----
If you are a user/developer of a paste-compatible framework/app (as If you are a user/developer of a paste-compatible framework/app (as
Pyramid, Pylons and Turbogears) you can use the gunicorn Pyramid, Pylons and Turbogears) you can use the
`--paste <http://docs.gunicorn.org/en/latest/settings.html#paste>`_ option `--paste <http://docs.gunicorn.org/en/latest/settings.html#paste>`_ option
to run your application. to run your application.
For example: For example::
gunicorn --paste development.ini -b :8080 --chdir /path/to/project $ gunicorn --paste development.ini -b :8080 --chdir /path/to/project
Or use a different application: Or use a different application::
gunicorn --paste development.ini#admin -b :8080 --chdir /path/to/project $ gunicorn --paste development.ini#admin -b :8080 --chdir /path/to/project
It is all here. No configuration files nor additional python modules to It is all here. No configuration files nor additional Python modules to write!
write !!