Commit 483dc85d authored by Levin Zimmermann's avatar Levin Zimmermann

.

parent 3904e45b
......@@ -10,18 +10,18 @@ import sys
from tempfile import TemporaryFile
import time
from six.moves.urllib.parse import quote
try:
from urllib import splitport
except ImportError: # six.PY3
from urllib.parse import splitport
from waitress.server import create_server
import ZConfig
import Zope2
from Zope2.Startup.run import make_wsgi_app
from Products.ERP5Type.patches.WSGIPublisher import publish_module
try:
from ZPublisher.WSGIPublisher import _MODULES
from ZPublisher.WSGIPublisher import publish_module
except ImportError:
# BBB Zope2
from Products.ERP5Type.patches.WSGIPublisher import publish_module
# this class licensed under the MIT license (stolen from pyramid_translogger)
class TransLogger(object):
......@@ -77,7 +77,7 @@ class TransLogger(object):
'HTTP_USER_AGENT': environ.get('HTTP_USER_AGENT', '-'),
}
message = self.format % d
self.logger.warn(message)
self.logger.info(message)
def app_wrapper(large_file_threshold=10<<20, webdav_ports=()):
......@@ -158,6 +158,90 @@ def createServer(application, logger, **kw):
server.addr = server.sockinfo[3]
return server
def runwsgi():
parser = argparse.ArgumentParser()
parser.add_argument('--event-log-file', help='Event log file')
parser.add_argument('--access-log-file', help='Access log file')
parser.add_argument('--long-request-log-file', help='Long requests log file')
parser.add_argument('-w', '--webdav', action='store_true')
parser.add_argument('address', help='<ip>:<port>')
parser.add_argument('zope_conf', help='path to zope.conf')
parser.add_argument('--timerserver-interval', help='Interval for timerserver', type=float)
args = parser.parse_args()
startup = os.path.dirname(Zope2.Startup.__file__)
if os.path.isfile(os.path.join(startup, 'wsgischema.xml')):
schema = ZConfig.loadSchema(os.path.join(startup, 'wsgischema.xml'))
else: # BBB
schema = ZConfig.loadSchema(os.path.join(startup, 'zopeschema.xml'))
conf, _ = ZConfig.loadConfig(schema, args.zope_conf)
# Configure logging previously handled by ZConfig/ZServer
logging.captureWarnings(True)
root_logger = logging.getLogger()
root_logger.setLevel(logging.INFO)
if args.event_log_file is None:
event_log_handler = logging.StreamHandler(sys.stdout)
else:
event_log_handler = logging.FileHandler(args.event_log_file)
event_log_handler.setFormatter(logging.Formatter(
"------\n%(asctime)s,%(msecs)d %(levelname)s %(name)s %(message)s",
"%Y-%m-%d %H:%M:%S"))
root_logger.addHandler(event_log_handler)
if args.access_log_file is None:
access_log_handler = logging.StreamHandler(sys.stdout)
else:
access_log_handler = logging.FileHandler(args.access_log_file)
access_log_handler.setLevel(logging.INFO)
access_log_logger = logging.getLogger('access')
access_log_logger.propagate = False
access_log_logger.addHandler(access_log_handler)
if args.long_request_log_file:
from Products.ERP5Type.patches import LongRequestLogger_dumper
long_request_log_handler = logging.FileHandler(args.long_request_log_file)
long_request_log_handler.setFormatter(logging.Formatter("%(asctime)s - %(message)s"))
LongRequestLogger_dumper.logger.propagate = False
LongRequestLogger_dumper.logger.addHandler(long_request_log_handler)
if conf.debug_mode:
console_handler = logging.StreamHandler(sys.stderr)
console_handler.setFormatter(logging.Formatter(
"%(asctime)s,%(msecs)d %(levelname)s %(name)s %(message)s",
"%Y-%m-%d %H:%M:%S"))
console_handler.setLevel(logging.NOTSET)
root_logger.addHandler(console_handler)
make_wsgi_app({}, zope_conf=args.zope_conf)
if six.PY2:
from Signals.SignalHandler import SignalHandler
SignalHandler.registerHandler(signal.SIGTERM, sys.exit)
else:
import warnings
warnings.warn("zope4py3: SignalHandling not implemented!")
if args.timerserver_interval:
import Products.TimerService
Products.TimerService.timerserver.TimerServer.TimerServer(
module='Zope2',
interval=args.timerserver_interval,
)
createServer(
app_wrapper(
large_file_threshold=getattr(conf, 'large_file_threshold', None),
webdav_ports=[int(args.address.rsplit(':', 1)[1])] if args.webdav else ()),
listen=args.address,
logger=access_log_logger,
threads=getattr(conf, 'zserver_threads', 4),
asyncore_use_poll=True,
# Prevent waitress from adding its own Via and Server response headers.
ident=None,
).run()
server = None
################################################################
......@@ -172,7 +256,7 @@ server = None
from twisted.web.wsgi import WSGIResource
from twisted.internet import protocol, reactor, endpoints
from twisted.web import server as twisted_server
from StringIO import StringIO
from io import StringIO
# I modified runwsgi() without thinking carefully.
# Very dirty code.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment