summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgeorgem <devnull@localhost>2008-07-22 16:16:58 +0000
committergeorgem <devnull@localhost>2008-07-22 16:16:58 +0000
commit95cc309a86d9b69802102b08dc8e85b6f3c377b5 (patch)
tree4f0b3d9f111065ad75245ecd020b313193d05fbc
parentd84c6dbe51bc40ab74d8053c90267bd676cbd339 (diff)
downloadcherrypy-95cc309a86d9b69802102b08dc8e85b6f3c377b5.tar.gz
Override _installSignalHandlers for flup servers so they don't try to
install handlers (which causes errors in Linux). Added FlupSCGIServer to servers.py. Add '' to the front of sys.path in cherryd so modules in the currect directory can be imported in Linux. Added scgi support to cherryd.
-rw-r--r--cherrypy/cherryd26
-rw-r--r--cherrypy/process/servers.py34
2 files changed, 52 insertions, 8 deletions
diff --git a/cherrypy/cherryd b/cherrypy/cherryd
index 7525a0d2..0b6241c7 100644
--- a/cherrypy/cherryd
+++ b/cherrypy/cherryd
@@ -8,8 +8,9 @@ from cherrypy.process import plugins, servers
def start(configfiles=None, daemonize=False, environment=None,
- fastcgi=False, pidfile=None, imports=None):
+ fastcgi=False, scgi=False, pidfile=None, imports=None):
"""Subscribe all engine plugins and start the engine."""
+ sys.path = [''] + sys.path
for i in imports or []:
exec "import %s" % i
@@ -35,8 +36,12 @@ def start(configfiles=None, daemonize=False, environment=None,
if hasattr(engine, "console_control_handler"):
engine.console_control_handler.subscribe()
- if fastcgi:
- # Turn off autoreload when using fastcgi.
+ if fastcgi and scgi:
+ # fastcgi and scgi aren't allowed together.
+ cherrypy.log.error("fastcgi and scgi aren't allowed together.", 'ENGINE')
+ sys.exit(1)
+ elif fastcgi or scgi:
+ # Turn off autoreload when using fastcgi or scgi.
cherrypy.config.update({'engine.autoreload_on': False})
cherrypy.server.unsubscribe()
@@ -45,10 +50,13 @@ def start(configfiles=None, daemonize=False, environment=None,
if sock_file:
bindAddress = sock_file
else:
- fastcgi_port = cherrypy.config.get('server.socket_port', 4000)
- fastcgi_bindaddr = cherrypy.config.get('server.socket_host', '0.0.0.0')
- bindAddress = (fastcgi_bindaddr, fastcgi_port)
- f = servers.FlupFCGIServer(application=cherrypy.tree, bindAddress=bindAddress)
+ flup_port = cherrypy.config.get('server.socket_port', 4000)
+ flup_bindaddr = cherrypy.config.get('server.socket_host', '0.0.0.0')
+ bindAddress = (flup_bindaddr, flup_port)
+ if fastcgi:
+ f = servers.FlupFCGIServer(application=cherrypy.tree, bindAddress=bindAddress)
+ else:
+ f = servers.FlupSCGIServer(application=cherrypy.tree, bindAddress=bindAddress)
s = servers.ServerAdapter(engine, httpserver=f, bind_addr=bindAddress)
s.subscribe()
@@ -74,6 +82,8 @@ if __name__ == '__main__':
help="apply the given config environment")
p.add_option('-f', action="store_true", dest='fastcgi',
help="start a fastcgi server instead of the default HTTP server")
+ p.add_option('-s', action="store_true", dest='scgi',
+ help="start a scgi server instead of the default HTTP server")
p.add_option('-i', '--import', action="append", dest='imports',
help="specify modules to import")
p.add_option('-p', '--pidfile', dest='pidfile', default=None,
@@ -81,6 +91,6 @@ if __name__ == '__main__':
options, args = p.parse_args()
start(options.config, options.daemonize,
- options.environment, options.fastcgi, options.pidfile,
+ options.environment, options.fastcgi, options.scgi, options.pidfile,
options.imports)
diff --git a/cherrypy/process/servers.py b/cherrypy/process/servers.py
index f4baf833..41636820 100644
--- a/cherrypy/process/servers.py
+++ b/cherrypy/process/servers.py
@@ -135,6 +135,7 @@ class FlupFCGIServer(object):
# line 156, in _restoreSignalHandlers
# for signum,handler in self._oldSIGs:
# AttributeError: 'WSGIServer' object has no attribute '_oldSIGs'
+ self.fcgiserver._installSignalHandlers = lambda: None
self.fcgiserver._oldSIGs = []
self.ready = False
@@ -152,6 +153,39 @@ class FlupFCGIServer(object):
self.fcgiserver._threadPool.maxSpare = 0
+class FlupSCGIServer(object):
+ """Adapter for a flup.server.scgi.WSGIServer."""
+
+ def __init__(self, *args, **kwargs):
+ from flup.server.scgi import WSGIServer
+ self.scgiserver = WSGIServer(*args, **kwargs)
+ # TODO: report this bug upstream to flup.
+ # If we don't set _oldSIGs on Windows, we get:
+ # File "C:\Python24\Lib\site-packages\flup\server\threadedserver.py",
+ # line 108, in run
+ # self._restoreSignalHandlers()
+ # File "C:\Python24\Lib\site-packages\flup\server\threadedserver.py",
+ # line 156, in _restoreSignalHandlers
+ # for signum,handler in self._oldSIGs:
+ # AttributeError: 'WSGIServer' object has no attribute '_oldSIGs'
+ self.scgiserver._installSignalHandlers = lambda: None
+ self.scgiserver._oldSIGs = []
+ self.ready = False
+
+ def start(self):
+ """Start the SCGI server."""
+ self.ready = True
+ self.scgiserver.run()
+
+ def stop(self):
+ """Stop the HTTP server."""
+ self.ready = False
+ # Forcibly stop the scgi server main event loop.
+ self.scgiserver._keepGoing = False
+ # Force all worker threads to die off.
+ self.scgiserver._threadPool.maxSpare = 0
+
+
def client_host(server_host):
"""Return the host on which a client can connect to the given listener."""
if server_host == '0.0.0.0':