Esempio n. 1
0
 def bootstrap(self):
     """
 Configure and create web app
 """
     self.log.always("\n ====== Starting DIRAC web app ====== \n")
     #Load required CFG files
     self.__loadWebAppCFGFiles()
     #Debug mode?
     devMode = Conf.devMode()
     if devMode:
         self.log.info("Configuring in developer mode...")
     #Calculating routes
     result = self.__handlerMgr.getRoutes()
     if not result['OK']:
         return result
     routes = result['Value']
     #Initialize the session data
     SessionData.setHandlers(self.__handlerMgr.getHandlers()['Value'])
     #Create the app
     tLoader = TemplateLoader(self.__handlerMgr.getPaths("template"))
     kw = dict(devMode=devMode,
               template_loader=tLoader,
               cookie_secret=Conf.cookieSecret(),
               log_function=self._logRequest)
     #Check processes if we're under a load balancert
     if Conf.balancer() and Conf.numProcesses() not in (0, 1):
         tornado.process.fork_processes(Conf.numProcesses(), max_restarts=0)
         kw['devMode'] = False
     #Configure tornado app
     self.__app = tornado.web.Application(routes, **kw)
     self.log.notice("Configuring HTTP on port %s" % (Conf.HTTPPort()))
     #Create the web servers
     srv = tornado.httpserver.HTTPServer(self.__app)
     port = Conf.HTTPPort()
     srv.listen(port)
     self.__servers[('http', port)] = srv
     if Conf.HTTPS():
         self.log.notice("Configuring HTTPS on port %s" % Conf.HTTPSPort())
         sslops = dict(certfile=Conf.HTTPSCert(),
                       keyfile=Conf.HTTPSKey(),
                       cert_reqs=ssl.CERT_OPTIONAL,
                       ca_certs=Conf.generateCAFile())
         self.log.debug(
             " - %s" %
             "\n - ".join(["%s = %s" % (k, sslops[k]) for k in sslops]))
         srv = tornado.httpserver.HTTPServer(self.__app, ssl_options=sslops)
         port = Conf.HTTPSPort()
         srv.listen(port)
         self.__servers[('https', port)] = srv
     return result
Esempio n. 2
0
 def bootstrap( self ):
   """
   Configure and create web app
   """
   self.log.always( "\n ====== Starting DIRAC web app ====== \n" )
   #Load required CFG files
   self.__loadWebAppCFGFiles()
   #Debug mode?
   devMode = Conf.devMode()
   if devMode:
     self.log.info( "Configuring in developer mode..." )
   #Calculating routes
   result = self.__handlerMgr.getRoutes()
   if not result[ 'OK' ]:
     return result
   routes = result[ 'Value' ]
   #Initialize the session data
   SessionData.setHandlers( self.__handlerMgr.getHandlers()[ 'Value' ] )
   #Create the app
   tLoader = TemplateLoader( self.__handlerMgr.getPaths( "template" ) )
   kw = dict( devMode = devMode, template_loader = tLoader, cookie_secret = Conf.cookieSecret(),
              log_function = self._logRequest )
   #Check processes if we're under a load balancert
   if Conf.balancer() and Conf.numProcesses() not in ( 0, 1 ):
     tornado.process.fork_processes( Conf.numProcesses(), max_restarts=0 )
     kw[ 'devMode' ] = False
   #Configure tornado app
   self.__app = tornado.web.Application( routes, **kw )
   self.log.notice( "Configuring HTTP on port %s" % ( Conf.HTTPPort() ) )
   #Create the web servers
   srv = tornado.httpserver.HTTPServer( self.__app )
   port = Conf.HTTPPort()
   srv.listen( port )
   self.__servers[ ( 'http', port ) ] = srv
   if Conf.HTTPS():
     self.log.notice( "Configuring HTTPS on port %s" % Conf.HTTPSPort() )
     sslops = dict( certfile = Conf.HTTPSCert(),
                    keyfile = Conf.HTTPSKey(),
                    cert_reqs = ssl.CERT_OPTIONAL,
                    ca_certs = Conf.generateCAFile() )
     self.log.debug( " - %s" % "\n - ".join( [ "%s = %s" % ( k, sslops[k] ) for k in sslops ] ) )
     srv = tornado.httpserver.HTTPServer( self.__app, ssl_options = sslops )
     port = Conf.HTTPSPort()
     srv.listen( port )
     self.__servers[ ( 'https', port ) ] = srv
   return result
Esempio n. 3
0
    def bootstrap(self):
        """
    Configure and create web app
    """
        self.log.always("\n ====== Starting DIRAC web app ====== \n")

        # Load required CFG files
        if not self._loadDefaultWebCFG(
        ):  # if we have a web.cfg under etc directory we use it, otherwise we use the configuration file defined by the developer
            self._loadWebAppCFGFiles()
        # Calculating routes
        result = self.__handlerMgr.getRoutes()
        if not result['OK']:
            return result
        routes = result['Value']
        # Initialize the session data
        SessionData.setHandlers(self.__handlerMgr.getHandlers()['Value'])
        # Create the app
        tLoader = TemplateLoader(self.__handlerMgr.getPaths("template"))
        kw = dict(debug=Conf.devMode(),
                  template_loader=tLoader,
                  cookie_secret=Conf.cookieSecret(),
                  log_function=self._logRequest,
                  autoreload=Conf.numProcesses() < 2)

        #please do no move this lines. The lines must be before the fork_processes
        signal.signal(signal.SIGTERM, self.stopChildProcesses)
        signal.signal(signal.SIGINT, self.stopChildProcesses)

        # Check processes if we're under a load balancert
        if Conf.balancer() and Conf.numProcesses() not in (0, 1):
            tornado.process.fork_processes(Conf.numProcesses(), max_restarts=0)
            kw['debug'] = False
        # Debug mode?
        if kw['debug']:
            self.log.info("Configuring in developer mode...")
        # Configure tornado app
        self.__app = tornado.web.Application(routes, **kw)
        self.log.notice("Configuring HTTP on port %s" % (Conf.HTTPPort()))
        # Create the web servers
        srv = tornado.httpserver.HTTPServer(self.__app, xheaders=True)
        port = Conf.HTTPPort()
        srv.listen(port)
        self.__servers[('http', port)] = srv

        Conf.generateRevokedCertsFile()  # it is used by nginx....

        if Conf.HTTPS():
            self.log.notice("Configuring HTTPS on port %s" % Conf.HTTPSPort())
            sslops = dict(certfile=Conf.HTTPSCert(),
                          keyfile=Conf.HTTPSKey(),
                          cert_reqs=ssl.CERT_OPTIONAL,
                          ca_certs=Conf.generateCAFile(),
                          ssl_version=ssl.PROTOCOL_TLSv1)

            sslprotocol = str(Conf.SSLProrocol())
            aviableProtocols = [i for i in dir(ssl) if i.find('PROTOCOL') == 0]
            if sslprotocol and sslprotocol != "":
                if (sslprotocol in aviableProtocols):
                    sslops['ssl_version'] = getattr(ssl, sslprotocol)
                else:
                    message = "%s protocol is not provided. The following protocols are provided: %s" % (
                        sslprotocol, str(aviableProtocols))
                    gLogger.warn(message)

            self.log.debug(
                " - %s" %
                "\n - ".join(["%s = %s" % (k, sslops[k]) for k in sslops]))
            srv = tornado.httpserver.HTTPServer(self.__app,
                                                ssl_options=sslops,
                                                xheaders=True)
            port = Conf.HTTPSPort()
            srv.listen(port)
            self.__servers[('https', port)] = srv
        else:
            #when NGINX is used then the Conf.HTTPS return False, it means tornado does not have to be configured using 443 port
            Conf.generateCAFile(
            )  # if we use Nginx we have to generate the cas as well...
        return result
Esempio n. 4
0
  def bootstrap( self ):
    """
    Configure and create web app
    """
    self.log.always( "\n ====== Starting DIRAC web app ====== \n" )

    # Load required CFG files
    if not self._loadDefaultWebCFG():  # if we have a web.cfg under etc directory we use it, otherwise we use the configuration file defined by the developer
      self._loadWebAppCFGFiles()
    # Calculating routes
    result = self.__handlerMgr.getRoutes()
    if not result[ 'OK' ]:
      return result
    routes = result[ 'Value' ]
    # Initialize the session data
    SessionData.setHandlers( self.__handlerMgr.getHandlers()[ 'Value' ] )
    # Create the app
    tLoader = TemplateLoader( self.__handlerMgr.getPaths( "template" ) )
    kw = dict( debug = Conf.devMode(), template_loader = tLoader, cookie_secret = Conf.cookieSecret(),
               log_function = self._logRequest, autoreload = Conf.numProcesses() < 2 )
    
    #please do no move this lines. The lines must be before the fork_processes
    signal.signal(signal.SIGTERM, self.stopChildProcesses)
    signal.signal(signal.SIGINT, self.stopChildProcesses)
    
    # Check processes if we're under a load balancert
    if Conf.balancer() and Conf.numProcesses() not in ( 0, 1 ):
      tornado.process.fork_processes( Conf.numProcesses(), max_restarts = 0 )
      kw[ 'debug' ] = False
    # Debug mode?
    if kw[ 'debug' ]:
      self.log.info( "Configuring in developer mode..." )
    # Configure tornado app
    self.__app = tornado.web.Application( routes, **kw )
    self.log.notice( "Configuring HTTP on port %s" % ( Conf.HTTPPort() ) )
    # Create the web servers
    srv = tornado.httpserver.HTTPServer( self.__app, xheaders = True )
    port = Conf.HTTPPort()
    srv.listen( port )
    self.__servers[ ( 'http', port ) ] = srv

    Conf.generateRevokedCertsFile()  # it is used by nginx....

    if Conf.HTTPS():
      self.log.notice( "Configuring HTTPS on port %s" % Conf.HTTPSPort() )
      sslops = dict( certfile = Conf.HTTPSCert(),
                     keyfile = Conf.HTTPSKey(),
                     cert_reqs = ssl.CERT_OPTIONAL,
                     ca_certs = Conf.generateCAFile(),
                     ssl_version = ssl.PROTOCOL_TLSv1 ) 

      sslprotocol = str( Conf.SSLProrocol() )
      aviableProtocols = [ i for i in dir( ssl ) if  i.find( 'PROTOCOL' ) == 0]
      if  sslprotocol and sslprotocol != "":
        if ( sslprotocol in aviableProtocols ):
          sslops['ssl_version'] = getattr( ssl, sslprotocol )
        else:
          message = "%s protocol is not provided. The following protocols are provided: %s" % ( sslprotocol, str( aviableProtocols ) )
          gLogger.warn( message )

      self.log.debug( " - %s" % "\n - ".join( [ "%s = %s" % ( k, sslops[k] ) for k in sslops ] ) )
      srv = tornado.httpserver.HTTPServer( self.__app, ssl_options = sslops, xheaders = True )
      port = Conf.HTTPSPort()
      srv.listen( port )
      self.__servers[ ( 'https', port ) ] = srv
    else:
      #when NGINX is used then the Conf.HTTPS return False, it means tornado does not have to be configured using 443 port
      Conf.generateCAFile()  # if we use Nginx we have to generate the cas as well...
    return result