[MERGE] --proxy mode added, using Werkzeug ProxyFix class.
bzr revid: vmt@openerp.com-20120210153500-689bnj0a1f51nvjc
This commit is contained in:
commit
679b64e865
|
@ -1,11 +1,15 @@
|
||||||
# Gunicorn sample configuration file.
|
# Gunicorn sample configuration file.
|
||||||
# See http://gunicorn.org/configure.html for more details.
|
# See http://gunicorn.org/configure.html for more details.
|
||||||
#
|
#
|
||||||
# To run OpenERP via Gunicorn, change the appropriate
|
# To run the OpenERP server via Gunicorn, change the appropriate
|
||||||
# settings below, in order to provide the parameters that
|
# settings below, in order to provide the parameters that
|
||||||
# would normally be passed in the command-line,
|
# would normally be passed in the command-line,
|
||||||
# (at least `bind` and `conf['addons_path']`), then execute:
|
# (at least `bind` and `conf['addons_path']`), then execute:
|
||||||
# $ gunicorn openerp:wsgi.application -c gunicorn.conf.py
|
# $ gunicorn openerp:wsgi.core.application -c gunicorn.conf.py
|
||||||
|
# or if you want to run it behind a reverse proxy, add the line
|
||||||
|
# import openerp.wsgi.proxied
|
||||||
|
# in this file and execute:
|
||||||
|
# $ gunicorn openerp:wsgi.proxied.application -c gunicorn.conf.py
|
||||||
|
|
||||||
import openerp
|
import openerp
|
||||||
|
|
||||||
|
@ -20,10 +24,10 @@ pidfile = '.gunicorn.pid'
|
||||||
workers = 4
|
workers = 4
|
||||||
|
|
||||||
# Some application-wide initialization is needed.
|
# Some application-wide initialization is needed.
|
||||||
on_starting = openerp.wsgi.on_starting
|
on_starting = openerp.wsgi.core.on_starting
|
||||||
when_ready = openerp.wsgi.when_ready
|
when_ready = openerp.wsgi.core.when_ready
|
||||||
pre_request = openerp.wsgi.pre_request
|
pre_request = openerp.wsgi.core.pre_request
|
||||||
post_request = openerp.wsgi.post_request
|
post_request = openerp.wsgi.core.post_request
|
||||||
|
|
||||||
# openerp request-response cycle can be quite long for
|
# openerp request-response cycle can be quite long for
|
||||||
# big reports for example
|
# big reports for example
|
||||||
|
|
|
@ -71,7 +71,7 @@ def start_services():
|
||||||
openerp.netsvc.Server.startAll()
|
openerp.netsvc.Server.startAll()
|
||||||
|
|
||||||
# Start the WSGI server.
|
# Start the WSGI server.
|
||||||
openerp.wsgi.start_server()
|
openerp.wsgi.core.start_server()
|
||||||
|
|
||||||
|
|
||||||
def stop_services():
|
def stop_services():
|
||||||
|
@ -80,7 +80,7 @@ def stop_services():
|
||||||
openerp.cron.cancel_all()
|
openerp.cron.cancel_all()
|
||||||
|
|
||||||
openerp.netsvc.Server.quitAll()
|
openerp.netsvc.Server.quitAll()
|
||||||
openerp.wsgi.stop_server()
|
openerp.wsgi.core.stop_server()
|
||||||
config = openerp.tools.config
|
config = openerp.tools.config
|
||||||
_logger.info("Initiating shutdown")
|
_logger.info("Initiating shutdown")
|
||||||
_logger.info("Hit CTRL-C again or send a second signal to force the shutdown.")
|
_logger.info("Hit CTRL-C again or send a second signal to force the shutdown.")
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#
|
#
|
||||||
# OpenERP, Open Source Management Solution
|
# OpenERP, Open Source Management Solution
|
||||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
|
||||||
|
# Copyright (C) 2010-2012 OpenERP s.a. (<http://openerp.com>).
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
@ -115,6 +116,8 @@ class configmanager(object):
|
||||||
help="specify the TCP port for the XML-RPC protocol", type="int")
|
help="specify the TCP port for the XML-RPC protocol", type="int")
|
||||||
group.add_option("--no-xmlrpc", dest="xmlrpc", action="store_false", my_default=True,
|
group.add_option("--no-xmlrpc", dest="xmlrpc", action="store_false", my_default=True,
|
||||||
help="disable the XML-RPC protocol")
|
help="disable the XML-RPC protocol")
|
||||||
|
group.add_option("--proxy-mode", dest="proxy_mode", action="store_true", my_default=False,
|
||||||
|
help="Enable correct behavior when behind a reverse proxy")
|
||||||
parser.add_option_group(group)
|
parser.add_option_group(group)
|
||||||
|
|
||||||
# XML-RPC / HTTPS
|
# XML-RPC / HTTPS
|
||||||
|
@ -391,7 +394,7 @@ class configmanager(object):
|
||||||
'language', 'translate_out', 'translate_in', 'overwrite_existing_translations',
|
'language', 'translate_out', 'translate_in', 'overwrite_existing_translations',
|
||||||
'debug_mode', 'smtp_ssl', 'load_language',
|
'debug_mode', 'smtp_ssl', 'load_language',
|
||||||
'stop_after_init', 'logrotate', 'without_demo', 'netrpc', 'xmlrpc', 'syslog',
|
'stop_after_init', 'logrotate', 'without_demo', 'netrpc', 'xmlrpc', 'syslog',
|
||||||
'list_db', 'xmlrpcs',
|
'list_db', 'xmlrpcs', 'proxy_mode',
|
||||||
'test_file', 'test_disable', 'test_commit', 'test_report_directory',
|
'test_file', 'test_disable', 'test_commit', 'test_report_directory',
|
||||||
'osv_memory_count_limit', 'osv_memory_age_limit', 'max_cron_threads',
|
'osv_memory_count_limit', 'osv_memory_age_limit', 'max_cron_threads',
|
||||||
'virtual_memory_limit', 'virtual_memory_reset', 'cpu_time_limit', 'unaccent',
|
'virtual_memory_limit', 'virtual_memory_reset', 'cpu_time_limit', 'unaccent',
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# OpenERP, Open Source Management Solution
|
||||||
|
# Copyright (C) 2012-2012 OpenERP s.a. (<http://openerp.com>).
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
""" WSGI stack
|
||||||
|
|
||||||
|
This module offers a WSGI interface to/from OpenERP.
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from . import core
|
||||||
|
|
||||||
|
# TODO: This is for the web addons, can be removed later.
|
||||||
|
register_wsgi_handler = core.register_wsgi_handler
|
||||||
|
|
||||||
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -2,7 +2,7 @@
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
# OpenERP, Open Source Management Solution
|
# OpenERP, Open Source Management Solution
|
||||||
# Copyright (C) 2011 OpenERP s.a. (<http://openerp.com>).
|
# Copyright (C) 2011-2012 OpenERP s.a. (<http://openerp.com>).
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU Affero General Public License as
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
@ -19,9 +19,9 @@
|
||||||
#
|
#
|
||||||
##############################################################################
|
##############################################################################
|
||||||
|
|
||||||
""" WSGI stuffs (proof of concept for now)
|
"""
|
||||||
|
|
||||||
This module offers a WSGI interface to OpenERP.
|
WSGI stack, common code.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ import traceback
|
||||||
import openerp
|
import openerp
|
||||||
import openerp.modules
|
import openerp.modules
|
||||||
import openerp.tools.config as config
|
import openerp.tools.config as config
|
||||||
import service.websrv_lib as websrv_lib
|
from ..service import websrv_lib
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -423,11 +423,20 @@ def serve():
|
||||||
port = config['xmlrpc_port']
|
port = config['xmlrpc_port']
|
||||||
try:
|
try:
|
||||||
import werkzeug.serving
|
import werkzeug.serving
|
||||||
|
if config['proxy_mode']:
|
||||||
|
from werkzeug.contrib.fixers import ProxyFix
|
||||||
|
app = ProxyFix(application)
|
||||||
|
suffix = ' (in proxy mode)'
|
||||||
|
else:
|
||||||
|
app = application
|
||||||
|
suffix = ''
|
||||||
httpd = werkzeug.serving.make_server(interface, port, application, threaded=True)
|
httpd = werkzeug.serving.make_server(interface, port, application, threaded=True)
|
||||||
_logger.info('HTTP service (werkzeug) running on %s:%s', interface, port)
|
_logger.info('HTTP service (werkzeug) running on %s:%s%s', interface, port, suffix)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import wsgiref.simple_server
|
import wsgiref.simple_server
|
||||||
_logger.warning('Werkzeug module unavailable, falling back to wsgiref.')
|
_logger.warning('Werkzeug module unavailable, falling back to wsgiref.')
|
||||||
|
if config['proxy_mode']:
|
||||||
|
_logger.warning('Werkzeug module unavailable, not using proxy mode.')
|
||||||
httpd = wsgiref.simple_server.make_server(interface, port, application)
|
httpd = wsgiref.simple_server.make_server(interface, port, application)
|
||||||
_logger.info('HTTP service (wsgiref) running on %s:%s', interface, port)
|
_logger.info('HTTP service (wsgiref) running on %s:%s', interface, port)
|
||||||
|
|
||||||
|
@ -438,7 +447,7 @@ def start_server():
|
||||||
|
|
||||||
The WSGI server can be shutdown with stop_server() below.
|
The WSGI server can be shutdown with stop_server() below.
|
||||||
"""
|
"""
|
||||||
threading.Thread(target=openerp.wsgi.serve).start()
|
threading.Thread(target=serve).start()
|
||||||
|
|
||||||
def stop_server():
|
def stop_server():
|
||||||
""" Initiate the shutdown of the WSGI server.
|
""" Initiate the shutdown of the WSGI server.
|
|
@ -0,0 +1,34 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# OpenERP, Open Source Management Solution
|
||||||
|
# Copyright (C) 2012 OpenERP s.a. (<http://openerp.com>).
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
WSGI entry point with Proxy mode (from Werkzeug).
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from werkzeug.contrib.fixers import ProxyFix
|
||||||
|
|
||||||
|
from . import core
|
||||||
|
|
||||||
|
application = ProxyFix(core.application)
|
||||||
|
|
||||||
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
Loading…
Reference in New Issue