1. cherrypy
  2. CherryPy


CherryPy / cherrypy / cherryd

The branch 'sendfile' does not exist.
#! /usr/bin/env python
"""The CherryPy daemon."""

import cherrypy
from cherrypy.process import plugins, servers

def start(configfile=None, daemonize=False, environment=None,
          fastcgi=False, pidfile=None):
    """Subscribe all engine plugins and start the engine."""
    if configfile:
    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 fastcgi:
        # turn off autoreload when using fastcgi
        cherrypy.config.update({'autoreload.on': False})
        fastcgi_port = cherrypy.config.get('server.socket_port', 4000)
        fastcgi_bindaddr = cherrypy.config.get('server.socket_host', '')
        bindAddress = (fastcgi_bindaddr, fastcgi_port)
        f = servers.FlupFCGIServer(application=cherrypy.tree, bindAddress=bindAddress)
        s = servers.ServerAdapter(engine, httpserver=f, bind_addr=bindAddress)
    # Always start the engine; this will start all other services

if __name__ == '__main__':
    from optparse import OptionParser
    p = OptionParser()
    p.add_option('-c', '--config', dest='config',
                 help="specify a config file")
    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('-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.pidfile)