Source

CherryPy / cherrypy / cherryd

The branch 'cherrypy-3.1.x' does not exist.
Diff from to

File cherrypy/cherryd

 
 
 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."""
-    for i in imports:
+    sys.path = [''] + sys.path
+    for i in imports or []:
         exec "import %s" % i
     
     for c in configfiles or []:
     if hasattr(engine, "console_control_handler"):
         engine.console_control_handler.subscribe()
     
-    if fastcgi:
-        # turn off autoreload when using fastcgi
-        cherrypy.config.update({'autoreload.on': False})
-        
+    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})
+        # Turn off the default HTTP server (which is subscribed by default).
         cherrypy.server.unsubscribe()
         
-        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)
+        sock_file = cherrypy.config.get('server.socket_file', None)
+        if sock_file:
+            bindAddress = sock_file
+        else:
+            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()
     
                  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,
     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)