mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
make sure address is a bytestring. While I'm here fix django
run_gunicorn command to use Config and set logger
This commit is contained in:
parent
d92b669117
commit
51a58e58c5
@ -100,7 +100,7 @@ class Config(object):
|
||||
def address(self):
|
||||
if not self.conf['bind']:
|
||||
raise RuntimeError("Listener address is not set")
|
||||
return util.parse_address(self.conf['bind'])
|
||||
return util.parse_address(util.to_bytestring(self.conf['bind']))
|
||||
|
||||
def _hook(self, hookname, *args):
|
||||
hook = self.conf.get(hookname)
|
||||
|
||||
@ -155,7 +155,7 @@ def paste_server(app, global_conf=None, host="127.0.0.1", port=None,
|
||||
|
||||
"""
|
||||
|
||||
bind_addr = util.parse_address(host, port)
|
||||
bind_addr = util.parse_address(util.to_bytestring(host), port)
|
||||
|
||||
# set others options
|
||||
debug = kwargs.get('debug')
|
||||
|
||||
@ -16,8 +16,9 @@ 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, UMASK, set_owner_process
|
||||
from gunicorn.util import parse_address
|
||||
from gunicorn.config import Config
|
||||
from gunicorn.main import daemonize, UMASK, set_owner_process, configure_logging
|
||||
from gunicorn.util import parse_address, to_bytestring
|
||||
|
||||
class Command(BaseCommand):
|
||||
option_list = BaseCommand.option_list + (
|
||||
@ -46,24 +47,21 @@ class Command(BaseCommand):
|
||||
if args:
|
||||
raise CommandError('Usage is runserver %s' % self.args)
|
||||
|
||||
bind = addrport or '127.0.0.1'
|
||||
addr = parse_address(bind)
|
||||
|
||||
options['bind'] = addrport or '127.0.0.1'
|
||||
conf = Config(options)
|
||||
|
||||
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', None)
|
||||
umask = options.get('umask', UMASK)
|
||||
|
||||
print "Validating models..."
|
||||
self.validate(display_num_errors=True)
|
||||
print "\nDjango version %s, using settings %r" % (django.get_version(), settings.SETTINGS_MODULE)
|
||||
|
||||
if isinstance(addr, basestring):
|
||||
print "Development server is running at unix:/%s" % addr
|
||||
if isinstance(conf.address, basestring):
|
||||
print "Development server is running at unix:/%s" % conf.address
|
||||
else:
|
||||
print "Development server is running at http://%s:%s/" % addr
|
||||
print "Development server is running at http://%s:%s/" % conf.address
|
||||
print "Quit the server with %s." % quit_command
|
||||
|
||||
# django.core.management.base forces the locale to en-us.
|
||||
@ -71,13 +69,14 @@ class Command(BaseCommand):
|
||||
|
||||
try:
|
||||
handler = AdminMediaHandler(WSGIHandler(), admin_media_path)
|
||||
arbiter = Arbiter(addr, workers, handler,
|
||||
pidfile=pidfile)
|
||||
if daemon:
|
||||
daemonize(umask)
|
||||
arbiter = Arbiter(conf.address, conf.workers, handler,
|
||||
pidfile=conf['pidfile'], config=conf)
|
||||
if conf['daemon']:
|
||||
daemonize(conf['umask'])
|
||||
else:
|
||||
os.setpgrp()
|
||||
set_owner_process(options.get("user"), options.get("group"))
|
||||
set_owner_process(conf["user"], conf["group"])
|
||||
configure_logging(conf)
|
||||
arbiter.run()
|
||||
except WSGIServerException, e:
|
||||
# Use helpful error messages instead of ugly tracebacks.
|
||||
|
||||
@ -163,3 +163,12 @@ def http_date(timestamp=None):
|
||||
day, monthname[month], year,
|
||||
hh, mm, ss)
|
||||
return s
|
||||
|
||||
def to_bytestring(s):
|
||||
""" convert to bytestring an unicode """
|
||||
if not isinstance(s, basestring):
|
||||
return s
|
||||
if isinstance(s, unicode):
|
||||
return s.encode('utf-8')
|
||||
else:
|
||||
return s
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user