Пример #1
0
def main():
    Script.parseCommandLine()
    args = Script.getPositionalArgs()
    if len(args) < 1:
        Script.showHelp(exitCode=1)

    # Script imports
    from DIRAC import gConfig
    from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller
    from DIRAC.FrameworkSystem.Utilities import MonitoringUtilities

    gComponentInstaller.exitOnError = True
    gComponentInstaller.getMySQLPasswords()
    for db in args:
        result = gComponentInstaller.installDatabase(db)
        if not result['OK']:
            print("ERROR: failed to correctly install %s" % db,
                  result['Message'])
        else:
            extension, system = result['Value']
            gComponentInstaller.addDatabaseOptionsToCS(gConfig,
                                                       system,
                                                       db,
                                                       overwrite=True)

            if db != 'InstalledComponentsDB':
                result = MonitoringUtilities.monitorInstallation(
                    'DB', system, db)
                if not result['OK']:
                    print(
                        "ERROR: failed to register installation in database: %s"
                        % result['Message'])
Пример #2
0
 def export_addDatabaseOptionsToCS(self, system, database, overwrite=False):
     """ Add the section with the database options to the CS
 """
     return gComponentInstaller.addDatabaseOptionsToCS(gConfig,
                                                       system,
                                                       database,
                                                       overwrite=overwrite)
Пример #3
0
                                     '  %s [option|cfgFile] ... DB ...' % Script.scriptName,
                                     'Arguments:',
                                     '  DB: Name of the Database (mandatory)'] ) )
Script.parseCommandLine()
args = Script.getPositionalArgs()
if len( args ) < 1:
  Script.showHelp()
  exit( -1 )

# Script imports
from DIRAC import gConfig
from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller
from DIRAC.FrameworkSystem.Utilities import MonitoringUtilities

__RCSID__ = "$Id$"

gComponentInstaller.exitOnError = True
gComponentInstaller.getMySQLPasswords()
for db in args:
  result = gComponentInstaller.installDatabase( db )
  if not result['OK']:
    print "ERROR: failed to correctly install %s" % db, result['Message']
  else:
    extension, system = result['Value']
    gComponentInstaller.addDatabaseOptionsToCS( gConfig, system, db, overwrite = True )

    if db != 'InstalledComponentsDB':
      result = MonitoringUtilities.monitorInstallation( 'DB', system, db )
      if not result[ 'OK' ]:
        print "ERROR: failed to register installation in database: %s" % result[ 'Message' ]
Пример #4
0
 def export_addDatabaseOptionsToCS( self, system, database, overwrite = False ):
   """ Add the section with the database options to the CS
   """
   return gComponentInstaller.addDatabaseOptionsToCS( gConfig, system, database, overwrite = overwrite )
  def do_install( self, args ):
    """
        Install various DIRAC components

        usage:

          install mysql
          install db <database>
          install service <system> <service> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ...
          install agent <system> <agent> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ...
          install executor <system> <executor> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ...
    """
    argss = args.split()
    if not argss:
      gLogger.notice( self.do_install.__doc__ )
      return

    option = argss[0]
    del argss[0]
    if option == "mysql":
      gLogger.notice( "Installing MySQL database, this can take a while ..." )
      client = SystemAdministratorClient( self.host, self.port )
      if gComponentInstaller.mysqlPassword == 'LocalConfig':
        gComponentInstaller.mysqlPassword = ''
      gComponentInstaller.getMySQLPasswords()
      result = client.installMySQL( gComponentInstaller.mysqlRootPwd, gComponentInstaller.mysqlPassword )
      if not result['OK']:
        self._errMsg( result['Message'] )
      else:
        gLogger.notice( "MySQL:", result['Value'] )
        gLogger.notice( "You might need to restart SystemAdministrator service to take new settings into account" )
    elif option == "db":
      if not argss:
        gLogger.notice( self.do_install.__doc__ )
        return
      database = argss[0]
      client = SystemAdministratorClient( self.host, self.port )

      result = client.getAvailableDatabases()
      if not result['OK']:
        self._errMsg( "Can not get database list: %s" % result['Message'] )
        return
      if not result['Value'].has_key( database ):
        self._errMsg( "Unknown database %s: " % database )
        return
      system = result['Value'][database]['System']
      setup = gConfig.getValue( '/DIRAC/Setup', '' )
      if not setup:
        self._errMsg( "Unknown current setup" )
        return
      instance = gConfig.getValue( '/DIRAC/Setups/%s/%s' % ( setup, system ), '' )
      if not instance:
        self._errMsg( "No instance defined for system %s" % system )
        self._errMsg( "\tAdd new instance with 'add instance %s <instance_name>'" % system )
        return

      if not gComponentInstaller.mysqlPassword:
        gComponentInstaller.mysqlPassword = '******'
      gComponentInstaller.getMySQLPasswords()
      result = client.installDatabase( database, gComponentInstaller.mysqlRootPwd )
      if not result['OK']:
        self._errMsg( result['Message'] )
        return
      extension, system = result['Value']

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return

      if database != 'InstalledComponentsDB':
        result = MonitoringUtilities.monitorInstallation( 'DB', system.replace( 'System', '' ), database, cpu = cpu, hostname = hostname )
        if not result['OK']:
          self._errMsg( result['Message'] )
          return
      # result = client.addDatabaseOptionsToCS( system, database )
      gComponentInstaller.mysqlHost = self.host
      result = client.getInfo()
      if not result['OK']:
        self._errMsg( result['Message'] )
      hostSetup = result['Value']['Setup']
      result = gComponentInstaller.addDatabaseOptionsToCS( gConfig, system, database, hostSetup, overwrite = True )
      if not result['OK']:
        self._errMsg( result['Message'] )
        return
      gLogger.notice( "Database %s from %s/%s installed successfully" % ( database, extension, system ) )
    elif option in self.runitComponents:
      if len( argss ) < 2:
        gLogger.notice( self.do_install.__doc__ )
        return

      system = argss[0]
      del argss[0]
      component = argss[0]
      del argss[0]

      specialOptions = {}
      module = ''
     
      for i in range(len(argss)):
        if argss[i] == "-m":
          specialOptions['Module'] = argss[i+1]
          module = argss[i+1]
        if argss[i] == "-p":
          opt,value = argss[i+1].split('=')
          specialOptions[opt] = value
      if module == component:
        module = ''

      client = SystemAdministratorClient( self.host, self.port )
      # First need to update the CS
      # result = client.addDefaultOptionsToCS( option, system, component )
      gComponentInstaller.host = self.host
      result = client.getInfo()
      if not result['OK']:
        self._errMsg( result['Message'] )
        return
      hostSetup = result['Value']['Setup']
    
      # Install Module section if not yet there
      if module:
        result = gComponentInstaller.addDefaultOptionsToCS( gConfig, option, system, module,
                                                            getCSExtensions(), hostSetup )
        # in case of Error we must stop, this can happen when the module name is wrong...
        if not result['OK']:
          self._errMsg( result['Message'] )
          return
        # Add component section with specific parameters only
        result = gComponentInstaller.addDefaultOptionsToCS( gConfig, option, system, component,
                                                            getCSExtensions(), hostSetup, specialOptions,
                                                            addDefaultOptions = True )
      else:
        # Install component section
        result = gComponentInstaller.addDefaultOptionsToCS( gConfig, option, system, component,
                                                            getCSExtensions(), hostSetup, specialOptions )

      if not result['OK']:
        self._errMsg( result['Message'] )
        return
      # Then we can install and start the component
      result = client.setupComponent( option, system, component, module )
      if not result['OK']:
        self._errMsg( result['Message'] )
        return
      compType = result['Value']['ComponentType']
      runit = result['Value']['RunitStatus']
      gLogger.notice( "%s %s_%s is installed, runit status: %s" % ( compType, system, component, runit ) )

      # And register it in the database
      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      if component == 'ComponentMonitoring':
        # Make sure that the service is running before trying to use it
        nTries = 0
        maxTries = 5
        mClient = ComponentMonitoringClient()
        result = mClient.ping()
        while not result[ 'OK' ] and nTries < maxTries:
          time.sleep( 3 )
          result = mClient.ping()
          nTries = nTries + 1

        if not result[ 'OK' ]:
          self._errMsg( 'ComponentMonitoring service taking too long to start. Installation will not be logged into the database' )
          return

        result = MonitoringUtilities.monitorInstallation( 'DB', system, 'InstalledComponentsDB', cpu = cpu, hostname = hostname )
        if not result['OK']:
          self._errMsg( 'Error registering installation into database: %s' % result[ 'Message' ] )
          return
      
      result = MonitoringUtilities.monitorInstallation( option, system, component, module, cpu = cpu, hostname = hostname )
      if not result['OK']:
        self._errMsg( 'Error registering installation into database: %s' % result[ 'Message' ] )
        return
    else:
      gLogger.notice( "Unknown option:", option )
Пример #6
0
  def do_install( self, args ):
    """
        Install various DIRAC components

        usage:

          install mysql
          install db <database>
          install service <system> <service> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ...
          install agent <system> <agent> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ...
          install executor <system> <executor> [-m <ModuleName>] [-p <Option>=<Value>] [-p <Option>=<Value>] ...
    """
    argss = args.split()
    if not argss:
      gLogger.notice( self.do_install.__doc__ )
      return

    option = argss[0]
    del argss[0]
    if option == "mysql":
      gLogger.notice( "Installing MySQL database, this can take a while ..." )
      client = SystemAdministratorClient( self.host, self.port )
      if gComponentInstaller.mysqlPassword == 'LocalConfig':
        gComponentInstaller.mysqlPassword = ''
      gComponentInstaller.getMySQLPasswords()
      result = client.installMySQL( gComponentInstaller.mysqlRootPwd, gComponentInstaller.mysqlPassword )
      if not result['OK']:
        self._errMsg( result['Message'] )
      else:
        gLogger.notice( "MySQL:", result['Value'] )
        gLogger.notice( "You might need to restart SystemAdministrator service to take new settings into account" )
    elif option == "db":
      if not argss:
        gLogger.notice( self.do_install.__doc__ )
        return
      database = argss[0]
      client = SystemAdministratorClient( self.host, self.port )

      result = client.getAvailableDatabases()
      if not result['OK']:
        self._errMsg( "Can not get database list: %s" % result['Message'] )
        return
      if not result['Value'].has_key( database ):
        self._errMsg( "Unknown database %s: " % database )
        return
      system = result['Value'][database]['System']
      setup = gConfig.getValue( '/DIRAC/Setup', '' )
      if not setup:
        self._errMsg( "Unknown current setup" )
        return
      instance = gConfig.getValue( '/DIRAC/Setups/%s/%s' % ( setup, system ), '' )
      if not instance:
        self._errMsg( "No instance defined for system %s" % system )
        self._errMsg( "\tAdd new instance with 'add instance %s <instance_name>'" % system )
        return

      if not gComponentInstaller.mysqlPassword:
        gComponentInstaller.mysqlPassword = '******'
      gComponentInstaller.getMySQLPasswords()
      result = client.installDatabase( database, gComponentInstaller.mysqlRootPwd )
      if not result['OK']:
        self._errMsg( result['Message'] )
        return
      extension, system = result['Value']

      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return

      if database != 'InstalledComponentsDB':
        result = MonitoringUtilities.monitorInstallation( 'DB', system.replace( 'System', '' ), database, cpu = cpu, hostname = hostname )
        if not result['OK']:
          self._errMsg( result['Message'] )
          return
      # result = client.addDatabaseOptionsToCS( system, database )
      gComponentInstaller.mysqlHost = self.host
      result = client.getInfo()
      if not result['OK']:
        self._errMsg( result['Message'] )
      hostSetup = result['Value']['Setup']
      result = gComponentInstaller.addDatabaseOptionsToCS( gConfig, system, database, hostSetup, overwrite = True )
      if not result['OK']:
        self._errMsg( result['Message'] )
        return
      gLogger.notice( "Database %s from %s/%s installed successfully" % ( database, extension, system ) )
    elif option in self.runitComponents:
      if len( argss ) < 2:
        gLogger.notice( self.do_install.__doc__ )
        return

      system = argss[0]
      del argss[0]
      component = argss[0]
      del argss[0]

      specialOptions = {}
      module = ''
     
      for i in range(len(argss)):
        if argss[i] == "-m":
          specialOptions['Module'] = argss[i+1]
          module = argss[i+1]
        if argss[i] == "-p":
          opt,value = argss[i+1].split('=')
          specialOptions[opt] = value
      if module == component:
        module = ''

      client = SystemAdministratorClient( self.host, self.port )
      # First need to update the CS
      # result = client.addDefaultOptionsToCS( option, system, component )
      gComponentInstaller.host = self.host
      result = client.getInfo()
      if not result['OK']:
        self._errMsg( result['Message'] )
        return
      hostSetup = result['Value']['Setup']
    
      # Install Module section if not yet there
      if module:
        result = gComponentInstaller.addDefaultOptionsToCS( gConfig, option, system, module,
                                                            getCSExtensions(), hostSetup )
        # in case of Error we must stop, this can happen when the module name is wrong...
        if not result['OK']:
          self._errMsg( result['Message'] )
          return
        # Add component section with specific parameters only
        result = gComponentInstaller.addDefaultOptionsToCS( gConfig, option, system, component,
                                                            getCSExtensions(), hostSetup, specialOptions,
                                                            addDefaultOptions = True )
      else:
        # Install component section
        result = gComponentInstaller.addDefaultOptionsToCS( gConfig, option, system, component,
                                                            getCSExtensions(), hostSetup, specialOptions )

      if not result['OK']:
        self._errMsg( result['Message'] )
        return
      # Then we can install and start the component
      result = client.setupComponent( option, system, component, module )
      if not result['OK']:
        self._errMsg( result['Message'] )
        return
      compType = result['Value']['ComponentType']
      runit = result['Value']['RunitStatus']
      gLogger.notice( "%s %s_%s is installed, runit status: %s" % ( compType, system, component, runit ) )

      # And register it in the database
      result = client.getHostInfo()
      if not result[ 'OK' ]:
        self._errMsg( result[ 'Message' ] )
        return
      else:
        cpu = result[ 'Value' ][ 'CPUModel' ]
      hostname = self.host
      if component == 'ComponentMonitoring':
        # Make sure that the service is running before trying to use it
        nTries = 0
        maxTries = 5
        mClient = ComponentMonitoringClient()
        result = mClient.ping()
        while not result[ 'OK' ] and nTries < maxTries:
          time.sleep( 3 )
          result = mClient.ping()
          nTries = nTries + 1

        if not result[ 'OK' ]:
          self._errMsg( 'ComponentMonitoring service taking too long to start. Installation will not be logged into the database' )
          return

        result = MonitoringUtilities.monitorInstallation( 'DB', system, 'InstalledComponentsDB', cpu = cpu, hostname = hostname )
        if not result['OK']:
          self._errMsg( 'Error registering installation into database: %s' % result[ 'Message' ] )
          return
      
      result = MonitoringUtilities.monitorInstallation( option, system, component, module, cpu = cpu, hostname = hostname )
      if not result['OK']:
        self._errMsg( 'Error registering installation into database: %s' % result[ 'Message' ] )
        return
    else:
      gLogger.notice( "Unknown option:", option )