From 6afaf608e39f3448611ddfa4bab74c7ed5a63334 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Sun, 31 Jan 2010 02:34:16 +0100 Subject: [PATCH] add daaemon option --- examples/djangotest/settings.py | 3 ++- gunicorn/management/commands/run_gunicorn.py | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/examples/djangotest/settings.py b/examples/djangotest/settings.py index cedf9937..4081555b 100755 --- a/examples/djangotest/settings.py +++ b/examples/djangotest/settings.py @@ -76,5 +76,6 @@ INSTALLED_APPS = ( 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', - 'djangotest.testing' + 'djangotest.testing', + 'gunicorn' ) diff --git a/gunicorn/management/commands/run_gunicorn.py b/gunicorn/management/commands/run_gunicorn.py index 7d1bf20b..03b7f596 100644 --- a/gunicorn/management/commands/run_gunicorn.py +++ b/gunicorn/management/commands/run_gunicorn.py @@ -10,6 +10,7 @@ from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException from django.core.handlers.wsgi import WSGIHandler from gunicorn.arbiter import Arbiter +from gunicorn.main import daemonize class Command(BaseCommand): option_list = BaseCommand.option_list + ( @@ -19,6 +20,8 @@ class Command(BaseCommand): help='Specifies the number of worker processes to use.'), make_option('--pid', dest='pidfile', default='', help='set the background PID file'), + make_option( '--daemon', dest='daemon', action="store_true", + help='Run daemonized in the background.'), ) help = "Starts a fully-functional Web server using gunicorn." args = '[optional port number, or ipaddr:port]' @@ -45,6 +48,7 @@ class Command(BaseCommand): admin_media_path = options.get('admin_media_path', '') workers = int(options.get('workers', '1')) + daemon = options.get('daemon') quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C' pidfile = options.get('pidfile') or None @@ -61,6 +65,8 @@ class Command(BaseCommand): handler = AdminMediaHandler(WSGIHandler(), admin_media_path) arbiter = Arbiter((addr, int(port)), workers, handler, pidfile=pidfile) + if daemon: + daemonize() arbiter.run() except WSGIServerException, e: # Use helpful error messages instead of ugly tracebacks.