mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
fix gunicorn paster. Now we have real HUP with paster. Also use paster
logging everywhere.
This commit is contained in:
parent
d546d490e5
commit
cae9b0bece
@ -5,7 +5,7 @@ paste.app_factory = log_app:app_factory
|
|||||||
use = egg:gunicorn#main
|
use = egg:gunicorn#main
|
||||||
host = 127.0.0.1
|
host = 127.0.0.1
|
||||||
port = 8080
|
port = 8080
|
||||||
|
workers = 3
|
||||||
|
|
||||||
[loggers]
|
[loggers]
|
||||||
keys=root
|
keys=root
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
# 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 logging
|
||||||
import os
|
import os
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import sys
|
import sys
|
||||||
@ -14,7 +15,29 @@ SERVER = loadwsgi.SERVER
|
|||||||
from gunicorn.app.base import Application
|
from gunicorn.app.base import Application
|
||||||
from gunicorn.config import Config
|
from gunicorn.config import Config
|
||||||
|
|
||||||
class PasterApplication(Application):
|
class PasterBaseApplication(Application):
|
||||||
|
|
||||||
|
def configure_logging(self):
|
||||||
|
if hasattr(self, "cfgfname"):
|
||||||
|
self.logger = logging.getLogger('gunicorn')
|
||||||
|
# from paste.script.command
|
||||||
|
parser = ConfigParser.ConfigParser()
|
||||||
|
parser.read([self.cfgfname])
|
||||||
|
if parser.has_section('loggers'):
|
||||||
|
if sys.version_info >= (2, 6):
|
||||||
|
from logging.config import fileConfig
|
||||||
|
else:
|
||||||
|
# Use our custom fileConfig -- 2.5.1's with a custom Formatter class
|
||||||
|
# and less strict whitespace (which were incorporated into 2.6's)
|
||||||
|
from paste.script.util.logging_config import fileConfig
|
||||||
|
|
||||||
|
config_file = os.path.abspath(self.cfgfname)
|
||||||
|
fileConfig(config_file, dict(__file__=config_file,
|
||||||
|
here=os.path.dirname(config_file)))
|
||||||
|
return
|
||||||
|
super(PasterApplication, self).configure_logging()
|
||||||
|
|
||||||
|
class PasterApplication(PasterBaseApplication):
|
||||||
|
|
||||||
def init(self, parser, opts, args):
|
def init(self, parser, opts, args):
|
||||||
if len(args) != 1:
|
if len(args) != 1:
|
||||||
@ -37,7 +60,6 @@ class PasterApplication(Application):
|
|||||||
def app_config(self):
|
def app_config(self):
|
||||||
cx = loadwsgi.loadcontext(SERVER, self.cfgurl, relative_to=self.relpath)
|
cx = loadwsgi.loadcontext(SERVER, self.cfgurl, relative_to=self.relpath)
|
||||||
gc, lc = cx.global_conf.copy(), cx.local_conf.copy()
|
gc, lc = cx.global_conf.copy(), cx.local_conf.copy()
|
||||||
|
|
||||||
cfg = {}
|
cfg = {}
|
||||||
|
|
||||||
host, port = lc.pop('host', ''), lc.pop('port', '')
|
host, port = lc.pop('host', ''), lc.pop('port', '')
|
||||||
@ -64,32 +86,21 @@ class PasterApplication(Application):
|
|||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
return loadapp(self.cfgurl, relative_to=self.relpath)
|
return loadapp(self.cfgurl, relative_to=self.relpath)
|
||||||
|
|
||||||
def configure_logging(self):
|
class PasterServerApplication(PasterBaseApplication):
|
||||||
# from paste.script.command
|
|
||||||
parser = ConfigParser.ConfigParser()
|
|
||||||
parser.read([self.cfgfname])
|
|
||||||
if parser.has_section('loggers'):
|
|
||||||
if sys.version_info >= (2, 6):
|
|
||||||
from logging.config import fileConfig
|
|
||||||
else:
|
|
||||||
# Use our custom fileConfig -- 2.5.1's with a custom Formatter class
|
|
||||||
# and less strict whitespace (which were incorporated into 2.6's)
|
|
||||||
from paste.script.util.logging_config import fileConfig
|
|
||||||
|
|
||||||
config_file = os.path.abspath(self.cfgfname)
|
|
||||||
fileConfig(config_file, dict(__file__=config_file,
|
|
||||||
here=os.path.dirname(config_file)))
|
|
||||||
else:
|
|
||||||
super(PasterApplication, self).configure_logging()
|
|
||||||
|
|
||||||
class PasterServerApplication(Application):
|
|
||||||
|
|
||||||
def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
|
def __init__(self, app, gcfg=None, host="127.0.0.1", port=None, *args, **kwargs):
|
||||||
self.cfg = Config()
|
self.cfg = Config()
|
||||||
self.app = app
|
self.app = app
|
||||||
self.callable = None
|
self.callable = None
|
||||||
|
|
||||||
|
gcfg = gcfg or {}
|
||||||
|
cfgfname = gcfg.get("__file__")
|
||||||
|
if cfgfname is not None:
|
||||||
|
self.cfgurl = 'config:%s' % cfgfname
|
||||||
|
self.relpath = os.path.dirname(cfgfname)
|
||||||
|
self.cfgfname = cfgfname
|
||||||
|
|
||||||
cfg = kwargs.copy()
|
cfg = kwargs.copy()
|
||||||
|
|
||||||
if port and not host.startswith("unix:"):
|
if port and not host.startswith("unix:"):
|
||||||
@ -109,7 +120,42 @@ class PasterServerApplication(Application):
|
|||||||
|
|
||||||
self.configure_logging()
|
self.configure_logging()
|
||||||
|
|
||||||
|
def load_config(self):
|
||||||
|
cx = loadwsgi.loadcontext(SERVER, self.cfgurl, relative_to=self.relpath)
|
||||||
|
gc, lc = cx.global_conf.copy(), cx.local_conf.copy()
|
||||||
|
cfg = {}
|
||||||
|
|
||||||
|
host, port = lc.pop('host', ''), lc.pop('port', '')
|
||||||
|
if host and port:
|
||||||
|
cfg['bind'] = '%s:%s' % (host, port)
|
||||||
|
elif host:
|
||||||
|
cfg['bind'] = host
|
||||||
|
|
||||||
|
cfg['workers'] = int(lc.get('workers', 1))
|
||||||
|
cfg['umask'] = int(lc.get('umask', 0))
|
||||||
|
cfg['default_proc_name'] = gc.get('__file__')
|
||||||
|
|
||||||
|
for k, v in gc.items():
|
||||||
|
if k not in self.cfg.settings:
|
||||||
|
continue
|
||||||
|
cfg[k] = v
|
||||||
|
|
||||||
|
for k, v in lc.items():
|
||||||
|
if k not in self.cfg.settings:
|
||||||
|
continue
|
||||||
|
|
||||||
|
cfg[k] = v
|
||||||
|
|
||||||
|
for k,v in cfg.items():
|
||||||
|
try:
|
||||||
|
self.cfg.set(k.lower(), v)
|
||||||
|
except:
|
||||||
|
sys.stderr.write("Invalid value for %s: %s\n\n" % (k, v))
|
||||||
|
raise
|
||||||
|
|
||||||
def load(self):
|
def load(self):
|
||||||
|
if hasattr(self, "cfgfname"):
|
||||||
|
return loadapp(self.cfgurl, relative_to=self.relpath)
|
||||||
return self.app
|
return self.app
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -118,7 +118,8 @@ class Arbiter(object):
|
|||||||
self.pidfile = Pidfile(self.cfg.pidfile)
|
self.pidfile = Pidfile(self.cfg.pidfile)
|
||||||
self.pidfile.create(self.pid)
|
self.pidfile.create(self.pid)
|
||||||
self.log.debug("Arbiter booted")
|
self.log.debug("Arbiter booted")
|
||||||
self.log.info("Listening at: %s" % self.LISTENER)
|
self.log.info("Listening at: %s (%s)" % (self.LISTENER,
|
||||||
|
self.pid))
|
||||||
self.cfg.when_ready(self)
|
self.cfg.when_ready(self)
|
||||||
|
|
||||||
def init_signals(self):
|
def init_signals(self):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user