mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
allows custom arbiter
This commit is contained in:
parent
8b9cb09b6b
commit
23927f39b1
@ -15,12 +15,14 @@ class Config(object):
|
|||||||
DEFAULT_CONFIG_FILE = 'gunicorn.conf.py'
|
DEFAULT_CONFIG_FILE = 'gunicorn.conf.py'
|
||||||
|
|
||||||
DEFAULTS = dict(
|
DEFAULTS = dict(
|
||||||
|
arbiter="egg:gunicorn",
|
||||||
backlog=2048,
|
backlog=2048,
|
||||||
bind='127.0.0.1:8000',
|
bind='127.0.0.1:8000',
|
||||||
daemon=False,
|
daemon=False,
|
||||||
debug=False,
|
debug=False,
|
||||||
default_proc_name = os.getcwd(),
|
default_proc_name = os.getcwd(),
|
||||||
group=None,
|
group=None,
|
||||||
|
keepalive=2,
|
||||||
logfile='-',
|
logfile='-',
|
||||||
loglevel='info',
|
loglevel='info',
|
||||||
pidfile=None,
|
pidfile=None,
|
||||||
@ -30,6 +32,7 @@ class Config(object):
|
|||||||
umask="0",
|
umask="0",
|
||||||
user=None,
|
user=None,
|
||||||
workers=1,
|
workers=1,
|
||||||
|
worker_connections=1000,
|
||||||
|
|
||||||
after_fork=lambda server, worker: server.log.info(
|
after_fork=lambda server, worker: server.log.info(
|
||||||
"Worker spawned (pid: %s)" % worker.pid),
|
"Worker spawned (pid: %s)" % worker.pid),
|
||||||
@ -93,7 +96,16 @@ class Config(object):
|
|||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self.conf.iteritems()
|
return self.conf.iteritems()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def arbiter(self):
|
||||||
|
uri = self.conf.get('arbiter', 'egg:gunicorn')
|
||||||
|
arbiter = util.parse_arbiter_uri(uri)
|
||||||
|
print arbiter
|
||||||
|
if hasattr(arbiter, 'setup'):
|
||||||
|
arbiter.setup()
|
||||||
|
return arbiter
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def workers(self):
|
def workers(self):
|
||||||
if not self.conf.get('workers'):
|
if not self.conf.get('workers'):
|
||||||
|
|||||||
@ -32,6 +32,9 @@ def options():
|
|||||||
help='Adress to listen on. Ex. 127.0.0.1:8000 or unix:/tmp/gunicorn.sock'),
|
help='Adress to listen on. Ex. 127.0.0.1:8000 or unix:/tmp/gunicorn.sock'),
|
||||||
op.make_option('-w', '--workers', dest='workers',
|
op.make_option('-w', '--workers', dest='workers',
|
||||||
help='Number of workers to spawn. [1]'),
|
help='Number of workers to spawn. [1]'),
|
||||||
|
op.make_option('-a', '--arbiter', dest='arbiter',
|
||||||
|
help="gunicorn arbiter entry point or module "+
|
||||||
|
"[egg:gunicorn#main]"),
|
||||||
op.make_option('-p','--pid', dest='pidfile',
|
op.make_option('-p','--pid', dest='pidfile',
|
||||||
help='set the background PID FILE'),
|
help='set the background PID FILE'),
|
||||||
op.make_option('-D', '--daemon', dest='daemon', action="store_true",
|
op.make_option('-D', '--daemon', dest='daemon', action="store_true",
|
||||||
@ -112,7 +115,7 @@ def main(usage, get_app):
|
|||||||
|
|
||||||
app = get_app(parser, opts, args)
|
app = get_app(parser, opts, args)
|
||||||
conf = Config(opts.__dict__, opts.config)
|
conf = Config(opts.__dict__, opts.config)
|
||||||
arbiter = Arbiter(conf.address, conf.workers, app, config=conf,
|
arbiter = conf.arbiter(conf.address, conf.workers, app, config=conf,
|
||||||
debug=conf['debug'], pidfile=conf['pidfile'])
|
debug=conf['debug'], pidfile=conf['pidfile'])
|
||||||
if conf['daemon']:
|
if conf['daemon']:
|
||||||
daemonize()
|
daemonize()
|
||||||
@ -147,7 +150,7 @@ def paste_server(app, global_conf=None, host="127.0.0.1", port=None,
|
|||||||
options['default_proc_name'] = options['__file__']
|
options['default_proc_name'] = options['__file__']
|
||||||
|
|
||||||
conf = Config(options)
|
conf = Config(options)
|
||||||
arbiter = Arbiter(conf.address, conf.workers, app, debug=conf["debug"],
|
arbiter = conf.arbiter(conf.address, conf.workers, app, debug=conf["debug"],
|
||||||
pidfile=conf["pidfile"], config=conf)
|
pidfile=conf["pidfile"], config=conf)
|
||||||
if conf["daemon"] :
|
if conf["daemon"] :
|
||||||
daemonize()
|
daemonize()
|
||||||
|
|||||||
@ -3,9 +3,11 @@
|
|||||||
# This file is part of gunicorn released under the MIT license.
|
# This file is part of gunicorn released under the MIT license.
|
||||||
# See the NOTICE for more information.
|
# See the NOTICE for more information.
|
||||||
|
|
||||||
|
|
||||||
import ctypes
|
import ctypes
|
||||||
import fcntl
|
import fcntl
|
||||||
import os
|
import os
|
||||||
|
import pkg_resources
|
||||||
import resource
|
import resource
|
||||||
import socket
|
import socket
|
||||||
import textwrap
|
import textwrap
|
||||||
@ -35,7 +37,30 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
def _setproctitle(title):
|
def _setproctitle(title):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def parse_arbiter_uri(uri):
|
||||||
|
if uri.startswith("egg:"):
|
||||||
|
# uses entry points
|
||||||
|
entry_str = uri.split("egg:")[1]
|
||||||
|
parsed_ept = entry_str.split("#", 1)
|
||||||
|
try:
|
||||||
|
dist, name = entry_str.rsplit("#",1)
|
||||||
|
except:
|
||||||
|
dist = entry_str
|
||||||
|
name = "main"
|
||||||
|
|
||||||
|
return pkg_resources.load_entry_point(dist, "gunicorn.arbiter",
|
||||||
|
name)
|
||||||
|
else:
|
||||||
|
components = uri.split('.')
|
||||||
|
if len(components) == 1:
|
||||||
|
raise RuntimeError("arbiter uri invalid")
|
||||||
|
klass = components.pop(-1)
|
||||||
|
mod = __import__('.'.join(components))
|
||||||
|
for comp in components[1:]:
|
||||||
|
mod = getattr(mod, comp)
|
||||||
|
return getattr(mod, klass)
|
||||||
|
|
||||||
def set_owner_process(uid,gid):
|
def set_owner_process(uid,gid):
|
||||||
""" set user and group of workers processes """
|
""" set user and group of workers processes """
|
||||||
if gid:
|
if gid:
|
||||||
@ -76,9 +101,8 @@ def get_maxfd():
|
|||||||
return maxfd
|
return maxfd
|
||||||
|
|
||||||
def close_on_exec(fd):
|
def close_on_exec(fd):
|
||||||
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
|
flags = fcntl.fcntl(fd, fcntl.F_GETFD) | fcntl.FD_CLOEXEC
|
||||||
flags |= fcntl.FD_CLOEXEC
|
fcntl.fcntl(fd, fcntl.F_SETFL, flags)
|
||||||
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
|
|
||||||
|
|
||||||
def set_non_blocking(fd):
|
def set_non_blocking(fd):
|
||||||
flags = fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK
|
flags = fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK
|
||||||
|
|||||||
6
setup.py
6
setup.py
@ -47,9 +47,13 @@ setup(
|
|||||||
gunicorn=gunicorn.main:run
|
gunicorn=gunicorn.main:run
|
||||||
gunicorn_django=gunicorn.main:run_django
|
gunicorn_django=gunicorn.main:run_django
|
||||||
gunicorn_paster=gunicorn.main:run_paster
|
gunicorn_paster=gunicorn.main:run_paster
|
||||||
|
|
||||||
|
[gunicorn.arbiter]
|
||||||
|
main=gunicorn.arbiter:Arbiter
|
||||||
|
|
||||||
|
|
||||||
[paste.server_runner]
|
[paste.server_runner]
|
||||||
main=gunicorn.main:paste_server
|
main=gunicorn.main:paste_server
|
||||||
""",
|
""",
|
||||||
test_suite = 'nose.collector',
|
test_suite = 'nose.collector',
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user