CherryPyFixTicketUrls2 / cherrypy / cherryd

#! /usr/bin/env python
"""The CherryPy daemon."""

import sys

import cherrypy
from cherrypy.process import plugins, servers

def start(configfiles=None, daemonize=False, environment=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
    for c in configfiles or []:
    engine = cherrypy.engine
    if environment is not None:
        cherrypy.config.update({'environment': environment})
    # Only daemonize if asked to.
    if daemonize:
        # Don't print anything to stdout/sterr.
        cherrypy.config.update({'log.screen': False})
    if pidfile:
        plugins.PIDFile(engine, pidfile).subscribe()
    if hasattr(engine, "signal_handler"):
    if hasattr(engine, "console_control_handler"):
    if fastcgi and scgi:
        # fastcgi and scgi aren't allowed together.
        cherrypy.log.error("fastcgi and scgi aren't allowed together.", 'ENGINE')
    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).
        sock_file = cherrypy.config.get('server.socket_file', None)
        if sock_file:
            bindAddress = sock_file
            flup_port = cherrypy.config.get('server.socket_port', 4000)
            flup_bindaddr = cherrypy.config.get('server.socket_host', '')
            bindAddress = (flup_bindaddr, flup_port)
        if fastcgi:
            f = servers.FlupFCGIServer(application=cherrypy.tree, bindAddress=bindAddress)
            f = servers.FlupSCGIServer(application=cherrypy.tree, bindAddress=bindAddress)
        s = servers.ServerAdapter(engine, httpserver=f, bind_addr=bindAddress)
    # Always start the engine; this will start all other services
        # Assume the error has been logged already via bus.log.

if __name__ == '__main__':
    from optparse import OptionParser
    p = OptionParser()
    p.add_option('-c', '--config', action="append", dest='config',
                 help="specify config file(s)")
    p.add_option('-d', action="store_true", dest='daemonize',
                 help="run the server as a daemon")
    p.add_option('-e', '--environment', dest='environment', default=None,
                 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,
                 help="store the process id in the given file")
    options, args = p.parse_args()
    start(options.config, options.daemonize,
          options.environment, options.fastcgi, options.scgi, options.pidfile,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.