Ejemplo n.º 1
0
    def __runServer(self):
        self.logger.info('Starting service')
        engine = cherrypy.engine

        # Set up Deamonization
        if self.options.daemonFlag:
            plugins.Daemonizer(engine).subscribe()
        self.logger.debug('Daemon mode: %s' % self.options.daemonFlag)

        if self.options.pidFile != None:
            plugins.PIDFile(engine, self.options.pidFile).subscribe()
        self.logger.debug('Using PID file: %s' % self.options.pidFile)

        sslCertFile = self.configurationManager.getSslCertFile()
        sslKeyFile = self.configurationManager.getSslKeyFile()
        sslCaCertFile = self.configurationManager.getSslCaCertFile()
        if sslCertFile != None and sslKeyFile != None:
            server.ssl_ca_certificate = None
            if sslCaCertFile != None:
                server.ssl_ca_certificate = self.options.sslCaCertFile
                self.logger.info('Using SSL CA cert file: %s' % sslCaCertFile)
            server.ssl_certificate = sslCertFile
            self.logger.info('Using SSL cert file: %s' % sslCertFile)

            server.ssl_private_key = sslKeyFile
            self.logger.info('Using SSL key file: %s' % sslKeyFile)

        server.ssl_module = 'builtin'
        #server.ssl_module = 'pyopenssl'

        # Increase timeout to prevent early SSL connection terminations
        server.socket_timeout = CdbWebServiceBase.DEFAULT_SERVER_SOCKET_TIMEOUT

        # Setup the signal handler to stop the application while running.
        if hasattr(engine, 'signal_handler'):
            engine.signal_handler.subscribe()
            self.modifySignalHandlers(engine)

        # Turn off autoreloader.
        self.logger.debug('Turning off autoreloader')
        engine.autoreload.unsubscribe()

        # Start the engine.
        try:
            self.logger.debug('Starting engine')
            engine.start()

            self.logger.debug('Starting background task')
            self.backgroundTaskManager.start()

            # Prepare cdb services.
            # Doing this before engine starts may cause issues with existing timers.
            self.logger.debug('Starting modules')
            self.initCdbModules()
            CdbModuleManager.getInstance().startModules()
        except Exception, ex:
            self.logger.exception('Service exiting: %s' % ex)
            CdbModuleManager.getInstance().stopModules()
            return cdbStatus.CDB_ERROR
Ejemplo n.º 2
0
 def getInstance(cls):
     from cdb.common.utility.cdbModuleManager import CdbModuleManager
     try:
         mgr = CdbModuleManager()
     except CdbModuleManager as ex:
         mgr = ex
     return mgr
Ejemplo n.º 3
0
    def initCdbModules(self):
        self.logger.debug('Initializing cdb modules')

        # For testing purposes only, use NoOp authorization principal retriever
        #self.logger.debug('Using NoOp Authorization Principal Retriever')
        #from cdb.common.impl.noOpAuthorizationPrincipalRetriever import NoOpAuthorizationPrincipalRetriever
        #principalRetriever = NoOpAuthorizationPrincipalRetriever()
        #AuthorizationManager.getInstance().addAuthorizationPrincipalRetriever(principalRetriever)

        # Add modules that will be started.
        moduleManager = CdbModuleManager.getInstance()
        self.logger.debug('Initialized cdb modules')
Ejemplo n.º 4
0
 def signalHandler(self):
     self.logger.debug('%s signal handler called' % self.signal)
     CdbModuleManager.getInstance().stopModules()
     self.oldSignalHandler()
Ejemplo n.º 5
0
            self.logger.debug('Starting background task')
            self.backgroundTaskManager.start()

            # Prepare cdb services.
            # Doing this before engine starts may cause issues with existing timers.
            self.logger.debug('Starting modules')
            self.initCdbModules()
            CdbModuleManager.getInstance().startModules()
        except Exception, ex:
            self.logger.exception('Service exiting: %s' % ex)
            CdbModuleManager.getInstance().stopModules()
            return cdbStatus.CDB_ERROR
        self.logger.info('Service ready')
        engine.block()
        CdbModuleManager.getInstance().stopModules()
        self.logger.info('Service done')
        return cdbStatus.CDB_OK

    # Run server instance.
    def run(self):
        self.prepareServer()
        sys.exit(self.__runServer())


####################################################################
# Testing

if __name__ == '__main__':
    pass