etwist/server.py
changeset 5679 0f2ded880d01
parent 5655 ef903fff826d
parent 5660 97343804414b
child 5694 ce2c108a9595
equal deleted inserted replaced
5676:aa04ccb8dd62 5679:0f2ded880d01
    40 from twisted.web.server import NOT_DONE_YET
    40 from twisted.web.server import NOT_DONE_YET
    41 
    41 
    42 from cubicweb.web import dumps
    42 from cubicweb.web import dumps
    43 
    43 
    44 from logilab.common.decorators import monkeypatch
    44 from logilab.common.decorators import monkeypatch
    45 from logilab.common.daemon import daemonize
       
    46 
    45 
    47 from cubicweb import AuthenticationError, ConfigurationError, CW_EVENT_MANAGER
    46 from cubicweb import AuthenticationError, ConfigurationError, CW_EVENT_MANAGER
    48 from cubicweb.web import Redirect, DirectResponse, StatusResponse, LogOut
    47 from cubicweb.web import Redirect, DirectResponse, StatusResponse, LogOut
    49 from cubicweb.web.application import CubicWebPublisher
    48 from cubicweb.web.application import CubicWebPublisher
    50 from cubicweb.web.http_headers import generateDateTime
    49 from cubicweb.web.http_headers import generateDateTime
   396     root_resource = CubicWebRootResource(config, vreg=vreg)
   395     root_resource = CubicWebRootResource(config, vreg=vreg)
   397     website = server.Site(root_resource)
   396     website = server.Site(root_resource)
   398     # serve it via standard HTTP on port set in the configuration
   397     # serve it via standard HTTP on port set in the configuration
   399     port = config['port'] or 8080
   398     port = config['port'] or 8080
   400     reactor.listenTCP(port, website)
   399     reactor.listenTCP(port, website)
   401     logger = getLogger('cubicweb.twisted')
       
   402     if not config.debugmode:
   400     if not config.debugmode:
   403         if sys.platform == 'win32':
   401         if sys.platform == 'win32':
   404             raise ConfigurationError("Under windows, you must use the service management "
   402             raise ConfigurationError("Under windows, you must use the service management "
   405                                      "commands (e.g : 'net start my_instance)'")
   403                                      "commands (e.g : 'net start my_instance)'")
   406         logger.info('instance started in the background on %s', root_resource.base_url)
   404         LOGGER.info('instance started in the background on %s', root_resource.base_url)
   407         if daemonize(config['pid-file']):
   405         if daemonize(config['pid-file']):
   408             return # child process
   406             return # child process
   409     root_resource.init_publisher() # before changing uid
   407     root_resource.init_publisher() # before changing uid
   410     if config['uid'] is not None:
   408     if config['uid'] is not None:
   411         try:
   409         try:
   413         except ValueError:
   411         except ValueError:
   414             from pwd import getpwnam
   412             from pwd import getpwnam
   415             uid = getpwnam(config['uid']).pw_uid
   413             uid = getpwnam(config['uid']).pw_uid
   416         os.setuid(uid)
   414         os.setuid(uid)
   417     root_resource.start_service()
   415     root_resource.start_service()
   418     logger.info('instance started on %s', root_resource.base_url)
   416     LOGGER.info('instance started on %s', root_resource.base_url)
   419     # avoid annoying warnign if not in Main Thread
   417     # avoid annoying warnign if not in Main Thread
   420     signals = threading.currentThread().getName() == 'MainThread'
   418     signals = threading.currentThread().getName() == 'MainThread'
   421     if config['profile']:
   419     if config['profile']:
   422         import cProfile
   420         import cProfile
   423         cProfile.runctx('reactor.run(installSignalHandlers=%s)' % signals,
   421         cProfile.runctx('reactor.run(installSignalHandlers=%s)' % signals,