add daaemon option

This commit is contained in:
Benoit Chesneau 2010-01-31 02:34:16 +01:00
parent 85e5b78ec5
commit 6afaf608e3
2 changed files with 8 additions and 1 deletions

View File

@ -76,5 +76,6 @@ INSTALLED_APPS = (
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.sites', 'django.contrib.sites',
'djangotest.testing' 'djangotest.testing',
'gunicorn'
) )

View File

@ -10,6 +10,7 @@ from django.core.servers.basehttp import AdminMediaHandler, WSGIServerException
from django.core.handlers.wsgi import WSGIHandler from django.core.handlers.wsgi import WSGIHandler
from gunicorn.arbiter import Arbiter from gunicorn.arbiter import Arbiter
from gunicorn.main import daemonize
class Command(BaseCommand): class Command(BaseCommand):
option_list = BaseCommand.option_list + ( option_list = BaseCommand.option_list + (
@ -19,6 +20,8 @@ class Command(BaseCommand):
help='Specifies the number of worker processes to use.'), help='Specifies the number of worker processes to use.'),
make_option('--pid', dest='pidfile', default='', make_option('--pid', dest='pidfile', default='',
help='set the background PID file'), 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." help = "Starts a fully-functional Web server using gunicorn."
args = '[optional port number, or ipaddr:port]' args = '[optional port number, or ipaddr:port]'
@ -45,6 +48,7 @@ class Command(BaseCommand):
admin_media_path = options.get('admin_media_path', '') admin_media_path = options.get('admin_media_path', '')
workers = int(options.get('workers', '1')) workers = int(options.get('workers', '1'))
daemon = options.get('daemon')
quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C' quit_command = (sys.platform == 'win32') and 'CTRL-BREAK' or 'CONTROL-C'
pidfile = options.get('pidfile') or None pidfile = options.get('pidfile') or None
@ -61,6 +65,8 @@ class Command(BaseCommand):
handler = AdminMediaHandler(WSGIHandler(), admin_media_path) handler = AdminMediaHandler(WSGIHandler(), admin_media_path)
arbiter = Arbiter((addr, int(port)), workers, handler, arbiter = Arbiter((addr, int(port)), workers, handler,
pidfile=pidfile) pidfile=pidfile)
if daemon:
daemonize()
arbiter.run() arbiter.run()
except WSGIServerException, e: except WSGIServerException, e:
# Use helpful error messages instead of ugly tracebacks. # Use helpful error messages instead of ugly tracebacks.