From 63d45ef1810789b715e9b446b96d86e068928e75 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Sat, 23 Jan 2010 16:46:49 +0100 Subject: [PATCH] gunicorn server factory for paster. --- README.rst | 19 +++++++++++++++++++ examples/pylonstest/development.ini | 2 +- gunicorn/main.py | 21 +++++++++++++++++++++ setup.py | 5 ++++- 4 files changed, 45 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index bb5018e6..39ca1330 100644 --- a/README.rst +++ b/README.rst @@ -37,16 +37,35 @@ Example with test app:: $ gunicorn --workers=2 test:app +Django projects ++++++++++++++++ + For django projects use the `gunicorn_django` command:: $ cd yourdjangoproject $ gunicorn_django --workers=2 +Paste-compatible projects ++++++++++++++++++++++++++ + For paste-compatible projects (like Pylons) use the `gunicorn_paste` command:: $ cd your pasteproject $ gunicorn_paste --workers=2 development.ini +or usual paster command:: + + $ cd your pasteproject + $ paster server development workers=2 + +In last case don't forget to add a server section for gunicorn. Here is an example that use +gunicorn as main server:: + + [server:main] + use = egg:gunicorn#main + host = 127.0.0.1 + port = 5000 + **WARNING:** diff --git a/examples/pylonstest/development.ini b/examples/pylonstest/development.ini index 92697151..4a14bdc7 100644 --- a/examples/pylonstest/development.ini +++ b/examples/pylonstest/development.ini @@ -11,7 +11,7 @@ smtp_server = localhost error_email_from = paste@localhost [server:main] -use = egg:Paste#http +use = egg:gunicorn#main host = 127.0.0.1 port = 5000 diff --git a/gunicorn/main.py b/gunicorn/main.py index c35f4825..066c54f4 100644 --- a/gunicorn/main.py +++ b/gunicorn/main.py @@ -54,4 +54,25 @@ def main(usage, get_app): app = get_app(parser, opts, args) arbiter = Arbiter((opts.host, opts.port), opts.workers, app) arbiter.run() + + + +def paste_server(app, global_conf=None, host="127.0.0.1", port=None, *args, **kw): + if not port: + if ':' in host: + host, port = host.split(':', 1) + else: + port = 8000 + bind_addr = (host, int(port)) + + if not global_conf: + workers=1 + else: + workers = int(global_conf.get('workers', 1)) + + arbiter = Arbiter(bind_addr, workers, app) + arbiter.run() + + + diff --git a/setup.py b/setup.py index 32b29319..abd42136 100644 --- a/setup.py +++ b/setup.py @@ -40,7 +40,10 @@ setup( include_package_data = True, scripts = ['bin/gunicorn', 'bin/gunicorn_django', 'bin/gunicorn_paste'], + entry_points=""" + [paste.server_runner] + main=gunicorn.main:paste_server + """, test_suite = 'nose.collector', - )