Changeset 1930
- Timestamp:
- 03/18/08 12:47:35
- Files:
-
- trunk/cherrypy/_cpconfig.py (modified) (2 diffs)
- trunk/cherrypy/_cptree.py (modified) (2 diffs)
- trunk/cherrypy/cherryd (moved) (moved from trunk/cherrypy/cherryd.py) (2 diffs)
- trunk/cherrypy/process/restctl.sh (deleted)
- trunk/cherrypy/process/restd.py (deleted)
- trunk/cherrypy/process/servers.py (modified) (1 diff)
- trunk/cherrypy/scaffold/__init__.py (modified) (1 diff)
- trunk/cherrypy/scaffold/cpdeploy.py (deleted)
- trunk/cherrypy/scaffold/example.conf (modified) (1 diff)
- trunk/cherrypy/scaffold/site.conf (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cpconfig.py
r1887 r1930 65 65 66 66 engine: Controls the 'application engine', including autoreload. 67 These can only be declared in the global config. 68 tree: Grafts cherrypy.Application objects onto cherrypy.tree. 67 69 These can only be declared in the global config. 68 70 hooks: Declares additional request-processing functions. … … 315 317 """Namespace handler for the 'tree' config namespace.""" 316 318 cherrypy.tree.graft(v, v.script_name) 317 cherrypy.engine.log("Mounted: %s on %s" % (v, v.script_name ))319 cherrypy.engine.log("Mounted: %s on %s" % (v, v.script_name or "/")) 318 320 Config.namespaces["tree"] = _tree_namespace_handler 319 321 trunk/cherrypy/_cptree.py
r1888 r1930 46 46 relative_urls = False 47 47 48 def __init__(self, root, script_name="" ):48 def __init__(self, root, script_name="", config=None): 49 49 self.log = _cplogging.LogManager(id(self), cherrypy.log.logger_root) 50 50 self.root = root … … 57 57 58 58 self.config = self.__class__.config.copy() 59 if config: 60 self.merge(config) 59 61 60 62 def __repr__(self): trunk/cherrypy/cherryd
r1926 r1930 2 2 """The CherryPy daemon.""" 3 3 4 import getopt5 import sys6 7 4 import cherrypy 8 from cherrypy.process import plugins 5 from cherrypy.process import plugins, servers 9 6 10 7 11 shortopts = ["d", "e"] 12 longopts = [] 13 14 # Help for restd command-line options. 15 help = """ 16 cherryd. Start the cherrypy daemon. 17 18 Usage: 19 cherryd <config filename> 20 21 """ 22 23 24 def start(options, configfile, *args): 8 def start(configfile=None, daemonize=False, environment=None, 9 fastcgi=False, pidfile=None): 10 """Subscribe all engine plugins and start the engine.""" 11 if configfile: 12 cherrypy.config.update(configfile) 13 25 14 engine = cherrypy.engine 26 15 27 siteconf = {} 28 cherrypy._cpconfig.merge(siteconf, configfile) 29 30 cherrypy.config.update(configfile) 31 32 if options.has_key('-e'): 33 cherrypy.config.update({'environment': options['-e']}) 34 35 # TODO: Make sure that log files are configurable from the conf file. 16 if environment is not None: 17 cherrypy.config.update({'environment': environment}) 36 18 37 19 # Only daemonize if asked to. 38 if options.has_key('-d'):20 if daemonize: 39 21 # Don't print anything to stdout/sterr. 40 22 cherrypy.config.update({'log.screen': False}) 41 23 plugins.Daemonizer(engine).subscribe() 42 24 43 if options.has_key('--pidfile'):44 plugins.PIDFile(engine, options['--pidfile']).subscribe()25 if pidfile: 26 plugins.PIDFile(engine, pidfile).subscribe() 45 27 46 28 cherrypy.signal_handler.subscribe() 47 29 48 # TODO: call a 'site setup' function (probably passing it siteconf). 49 50 if options.has_key('--fastcgi'): 30 if fastcgi: 51 31 # turn off autoreload when using fastcgi 52 32 cherrypy.config.update({'autoreload.on': False}) … … 57 37 fastcgi_bindaddr = cherrypy.config.get('server.socket_host', '0.0.0.0') 58 38 bindAddress = (fastcgi_bindaddr, fastcgi_port) 59 try: 60 # Always start the engine; this will start all other services 61 engine.start() 62 63 from flup.server.fcgi import WSGIServer 64 engine.log('Serving FastCGI on %s:%d' % bindAddress) 65 engine.fcgi = WSGIServer(application=wsgiapp, 66 bindAddress=bindAddress) 67 engine.fcgi.run() 68 engine.log('FastCGI Server on %s:%d shut down' % bindAddress) 69 finally: 70 engine.stop() 71 else: 72 # Always start the engine; this will start all other services 73 s = cherrypy.server 74 s.httpserver, s.bind_addr = s.httpserver_from_self() 75 s.httpserver.wsgi_app = wsgiapp 76 engine.start() 77 engine.block() 39 f = servers.FlupFCGIServer(application=cherrypy.tree, bindAddress=bindAddress) 40 s = servers.ServerAdapter(engine, httpserver=f, bind_addr=bindAddress) 41 s.subscribe() 42 43 # Always start the engine; this will start all other services 44 engine.start() 45 engine.block() 78 46 79 47 80 48 if __name__ == '__main__': 81 try: 82 opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts) 83 except getopt.GetoptError: 84 print help 85 sys.exit(2) 49 from optparse import OptionParser 86 50 87 start(dict(opts), *tuple(args)) 51 p = OptionParser() 52 p.add_option('-c', '--config', dest='config', 53 help="specify a config file") 54 p.add_option('-d', action="store_true", dest='daemonize', 55 help="run the server as a daemon") 56 p.add_option('-e', '--environment', dest='environment', default=None, 57 help="apply the given config environment") 58 p.add_option('-f', action="store_true", dest='fastcgi', 59 help="start a fastcgi server instead of the default HTTP server") 60 p.add_option('-p', '--pidfile', dest='pidfile', default=None, 61 help="store the process id in the given file") 62 options, args = p.parse_args() 63 64 start(options.config, options.daemonize, 65 options.environment, options.fastcgi, options.pidfile) 66 trunk/cherrypy/process/servers.py
r1830 r1930 122 122 123 123 124 class FlupFCGIServer(object): 125 """Adapter for a flup.server.fcgi.WSGIServer.""" 126 127 def __init__(self, *args, **kwargs): 128 from flup.server.fcgi import WSGIServer 129 self.fcgiserver = WSGIServer(*args, **kwargs) 130 # TODO: report this bug upstream to flup. 131 # If we don't set _oldSIGs on Windows, we get: 132 # File "C:\Python24\Lib\site-packages\flup\server\threadedserver.py", 133 # line 108, in run 134 # self._restoreSignalHandlers() 135 # File "C:\Python24\Lib\site-packages\flup\server\threadedserver.py", 136 # line 156, in _restoreSignalHandlers 137 # for signum,handler in self._oldSIGs: 138 # AttributeError: 'WSGIServer' object has no attribute '_oldSIGs' 139 self.fcgiserver._oldSIGs = [] 140 self.ready = False 141 142 def start(self): 143 """Start the FCGI server.""" 144 self.ready = True 145 self.fcgiserver.run() 146 147 def stop(self): 148 """Stop the HTTP server.""" 149 self.ready = False 150 # Forcibly stop the fcgi server main event loop. 151 self.fcgiserver._keepGoing = False 152 # Force all worker threads to die off. 153 self.fcgiserver._threadPool.maxSpare = 0 154 155 124 156 def client_host(server_host): 125 157 """Return the host on which a client can connect to the given listener.""" trunk/cherrypy/scaffold/__init__.py
r1864 r1930 9 9 Change to this directory and run: 10 10 11 python c pdeploy.py --config=example.conf11 python cherrypy\cherryd cherrypy\scaffold\site.conf 12 12 13 13 """ trunk/cherrypy/scaffold/example.conf
r1863 r1930 1 [global]2 # Uncomment this when you're done developing3 #environment: "production"4 5 server.socket_host: "0.0.0.0"6 server.socket_port: 80887 8 9 1 [/] 10 2 log.error_file: "error.log"

