[IMP] wsgi: provide the start- and stop-server functions.
bzr revid: vmt@openerp.com-20110914150603-zu6zh4v7pmnchvf3
This commit is contained in:
parent
46ad605226
commit
d743353e16
|
@ -155,7 +155,7 @@ def start_services():
|
||||||
openerp.netsvc.Server.startAll()
|
openerp.netsvc.Server.startAll()
|
||||||
|
|
||||||
# Start the WSGI server.
|
# Start the WSGI server.
|
||||||
threading.Thread(target=openerp.wsgi.serve).start()
|
openerp.wsgi.start_server()
|
||||||
|
|
||||||
# Variable keeping track of the number of calls to the signal handler defined
|
# Variable keeping track of the number of calls to the signal handler defined
|
||||||
# below. This variable is monitored by ``quit_on_signals()``.
|
# below. This variable is monitored by ``quit_on_signals()``.
|
||||||
|
@ -210,6 +210,7 @@ def quit_on_signals():
|
||||||
|
|
||||||
openerp.netsvc.Agent.quit()
|
openerp.netsvc.Agent.quit()
|
||||||
openerp.netsvc.Server.quitAll()
|
openerp.netsvc.Server.quitAll()
|
||||||
|
openerp.wsgi.stop_server()
|
||||||
config = openerp.tools.config
|
config = openerp.tools.config
|
||||||
if config['pidfile']:
|
if config['pidfile']:
|
||||||
os.unlink(config['pidfile'])
|
os.unlink(config['pidfile'])
|
||||||
|
|
|
@ -34,6 +34,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
|
import threading
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import openerp
|
import openerp
|
||||||
|
@ -171,10 +172,10 @@ def http_to_wsgi(http_dir):
|
||||||
server = Dummy()
|
server = Dummy()
|
||||||
server.server_name = environ['SERVER_NAME']
|
server.server_name = environ['SERVER_NAME']
|
||||||
server.server_port = int(environ['SERVER_PORT'])
|
server.server_port = int(environ['SERVER_PORT'])
|
||||||
con = openerp.service.websrv_lib.noconnection(environ['gunicorn.socket']) # None TODO
|
|
||||||
|
|
||||||
# Initialize the underlying handler and associated auth. provider.
|
# Initialize the underlying handler and associated auth. provider.
|
||||||
handler = http_dir.instanciate_handler(openerp.service.websrv_lib.noconnection(con), environ['REMOTE_ADDR'], server)
|
con = openerp.service.websrv_lib.noconnection(environ['wsgi.input'])
|
||||||
|
handler = http_dir.instanciate_handler(con, environ['REMOTE_ADDR'], server)
|
||||||
|
|
||||||
# Populate the handler as if it is called by a regular HTTP server
|
# Populate the handler as if it is called by a regular HTTP server
|
||||||
# and the request is already parsed.
|
# and the request is already parsed.
|
||||||
|
@ -197,7 +198,6 @@ def http_to_wsgi(http_dir):
|
||||||
# Darwin 9.x.x webdav clients will report "HTTP/1.0" to us, while they support (and need) the
|
# Darwin 9.x.x webdav clients will report "HTTP/1.0" to us, while they support (and need) the
|
||||||
# authorisation features of HTTP/1.1
|
# authorisation features of HTTP/1.1
|
||||||
if request_version != 'HTTP/1.1' and ('Darwin/9.' not in handler.headers.get('User-Agent', '')):
|
if request_version != 'HTTP/1.1' and ('Darwin/9.' not in handler.headers.get('User-Agent', '')):
|
||||||
print 'self.log_error("Cannot require auth at %s", self.request_version)'
|
|
||||||
start_response("403 Forbidden", [])
|
start_response("403 Forbidden", [])
|
||||||
return []
|
return []
|
||||||
start_response("401 Authorization required", [
|
start_response("401 Authorization required", [
|
||||||
|
@ -208,7 +208,6 @@ def http_to_wsgi(http_dir):
|
||||||
])
|
])
|
||||||
return ['Blah'] # self.auth_required_msg
|
return ['Blah'] # self.auth_required_msg
|
||||||
except websrv_lib.AuthRejectedExc,e:
|
except websrv_lib.AuthRejectedExc,e:
|
||||||
print '("Rejected auth: %s" % e.args[0])'
|
|
||||||
start_response("403 %s" % (e.args[0],), [])
|
start_response("403 %s" % (e.args[0],), [])
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@ -289,8 +288,11 @@ def application(environ, start_response):
|
||||||
start_response('404 Not Found', [('Content-Type', 'text/plain'), ('Content-Length', str(len(response)))])
|
start_response('404 Not Found', [('Content-Type', 'text/plain'), ('Content-Length', str(len(response)))])
|
||||||
return [response]
|
return [response]
|
||||||
|
|
||||||
|
# The WSGI server, started by start_server(), stopped by stop_server().
|
||||||
|
httpd = None
|
||||||
|
|
||||||
def serve():
|
def serve():
|
||||||
""" Serve XMLRPC requests via werkzeug development server.
|
""" Serve HTTP requests via werkzeug development server.
|
||||||
|
|
||||||
If werkzeug can not be imported, we fall back to wsgiref's simple_server.
|
If werkzeug can not be imported, we fall back to wsgiref's simple_server.
|
||||||
|
|
||||||
|
@ -298,6 +300,8 @@ def serve():
|
||||||
thread.
|
thread.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
global httpd
|
||||||
|
|
||||||
# TODO Change the xmlrpc_port option to http_port.
|
# TODO Change the xmlrpc_port option to http_port.
|
||||||
try:
|
try:
|
||||||
import werkzeug.serving
|
import werkzeug.serving
|
||||||
|
@ -312,6 +316,21 @@ def serve():
|
||||||
|
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
|
|
||||||
|
def start_server():
|
||||||
|
""" Call serve() in its own thread.
|
||||||
|
|
||||||
|
The WSGI server can be shutdown with stop_server() below.
|
||||||
|
"""
|
||||||
|
threading.Thread(target=openerp.wsgi.serve).start()
|
||||||
|
|
||||||
|
def stop_server():
|
||||||
|
""" Initiate the shutdown of the WSGI server.
|
||||||
|
|
||||||
|
The server is supposed to have been started by start_server() above.
|
||||||
|
"""
|
||||||
|
if httpd:
|
||||||
|
httpd.shutdown()
|
||||||
|
|
||||||
# Master process id, can be used for signaling.
|
# Master process id, can be used for signaling.
|
||||||
arbiter_pid = None
|
arbiter_pid = None
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue