Esempio n. 1
0
 def export_addDefaultOptionsToCS(self,
                                  componentType,
                                  system,
                                  component,
                                  overwrite=False):
     """ Add default component options to the global CS or to the local options
 """
     return gComponentInstaller.addDefaultOptionsToCS(gConfig,
                                                      componentType,
                                                      system,
                                                      component,
                                                      getCSExtensions(),
                                                      overwrite=overwrite)
Esempio n. 2
0
 def export_addDefaultOptionsToCS( self, componentType, system, component, overwrite = False ):
   """ Add default component options to the global CS or to the local options
   """
   return gComponentInstaller.addDefaultOptionsToCS( gConfig, componentType, system, component,
                                                     getCSExtensions(),
                                                     overwrite = overwrite )
Esempio n. 3
0
componentType = args[0]

if len(args) == 2:
    system, component = args[1].split("/")
else:
    system = args[1]
    component = args[2]

# imports
from DIRAC import gConfig
from DIRAC import exit as DIRACexit

from DIRAC.Core.Utilities.Extensions import extensionsByPriority
from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller

#

gComponentInstaller.exitOnError = True

result = gComponentInstaller.addDefaultOptionsToCS(gConfig,
                                                   componentType,
                                                   system,
                                                   component,
                                                   extensionsByPriority(),
                                                   specialOptions={},
                                                   overwrite=False)
if not result["OK"]:
    print("ERROR:", result["Message"])
else:
    DIRACexit()
Esempio n. 4
0
  DIRACexit(1)
else:
  availableComponents = result['Value']

for compType in availableComponents:
  if system in availableComponents[compType] and compOrMod in availableComponents[compType][system]:
    cType = compType[:-1].lower()
    break

if not cType:
  gLogger.error('Component %s/%s is not available for installation' % (system, component))
  DIRACexit(1)

if module:
  result = gComponentInstaller.addDefaultOptionsToCS(gConfig, cType, system, module,
                                                     getCSExtensions(),
                                                     overwrite=overwrite)
  result = gComponentInstaller.addDefaultOptionsToCS(gConfig, cType, system, component,
                                                     getCSExtensions(),
                                                     specialOptions=specialOptions,
                                                     overwrite=overwrite,
                                                     addDefaultOptions=False)
else:
  result = gComponentInstaller.addDefaultOptionsToCS(gConfig, cType, system, component,
                                                     getCSExtensions(),
                                                     specialOptions=specialOptions,
                                                     overwrite=overwrite)

if not result['OK']:
  gLogger.error(result['Message'])
  DIRACexit(1)
  DIRACexit( 1 )
else:
  availableComponents = result[ 'Value' ]

for compType in availableComponents:
  if system in availableComponents[ compType ] and component in availableComponents[ compType ][ system ]:
    cType = compType[:-1].lower()
    break

if not cType:
  gLogger.error( 'Component %s/%s is not available for installation' % ( system, component ) )
  DIRACexit( 1 )

if module:
  result = gComponentInstaller.addDefaultOptionsToCS( gConfig, cType, system, module,
                                                      getCSExtensions(),
                                                      overwrite = overwrite )
  result = gComponentInstaller.addDefaultOptionsToCS( gConfig, cType, system, component,
                                                      getCSExtensions(),
                                                      specialOptions = specialOptions,
                                                      overwrite = overwrite,
                                                      addDefaultOptions = False )
else:
  result = gComponentInstaller.addDefaultOptionsToCS( gConfig, cType, system, component,
                                                      getCSExtensions(),
                                                      specialOptions = specialOptions,
                                                      overwrite = overwrite )

if not result[ 'OK' ]:
  gLogger.error( result[ 'Message' ] )
  DIRACexit( 1 )
Esempio n. 6
0
Script.setUsageMessage(
    '\n'.join(
        [
            __doc__.split('\n')[1],
            'Usage:',
            '  %s [option|cfgfile] ... ComponentType System Component|System/Component' %
            Script.scriptName,
            'Arguments:',
            '  ComponentType:  Name of the ComponentType (ie: agent)',
            '  System:  Name of the DIRAC system (ie: WorkloadManagement)',
            '  component:   Name of the DIRAC component (ie: JobCleaningAgent)']))
Script.parseCommandLine()
args = Script.getPositionalArgs()

componentType = args[0]

if len(args) == 2:
  system, component = args[1].split('/')
else:
  system = args[1]
  component = args[2]

result = gComponentInstaller.addDefaultOptionsToCS(gConfig, componentType, system, component,
                                                   getCSExtensions(),
                                                   specialOptions={},
                                                   overwrite=False)
if not result['OK']:
  print "ERROR:", result['Message']
else:
  DIRACexit()
Esempio n. 7
0
def main():
    global overwrite
    global specialOptions
    global module
    global specialOptions

    from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller

    gComponentInstaller.exitOnError = True

    Script.registerSwitch("w", "overwrite",
                          "Overwrite the configuration in the global CS",
                          setOverwrite)
    Script.registerSwitch("m:", "module=",
                          "Python module name for the component code",
                          setModule)
    Script.registerSwitch("p:", "parameter=", "Special component option ",
                          setSpecialOption)
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument((
        "System/Component: Full component name (ie: WorkloadManagement/Matcher)",
        "System:           Name of the DIRAC system (ie: WorkloadManagement)",
    ))
    Script.registerArgument(
        " Component:        Name of the DIRAC service (ie: Matcher)",
        mandatory=False)

    Script.parseCommandLine()
    args = Script.getPositionalArgs()

    if len(args) == 1:
        args = args[0].split("/")

    if len(args) != 2:
        Script.showHelp(exitCode=1)

    system = args[0]
    component = args[1]
    compOrMod = module or component

    result = gComponentInstaller.getSoftwareComponents(extensionsByPriority())
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    availableComponents = result["Value"]

    for compType in availableComponents:
        if system in availableComponents[
                compType] and compOrMod in availableComponents[compType][
                    system]:
            cType = compType[:-1].lower()
            break
    else:
        gLogger.error("Component %s/%s is not available for installation" %
                      (system, component))
        DIRACexit(1)

    if module:
        result = gComponentInstaller.addDefaultOptionsToCS(
            gConfig,
            cType,
            system,
            module,
            extensionsByPriority(),
            overwrite=overwrite)
        result = gComponentInstaller.addDefaultOptionsToCS(
            gConfig,
            cType,
            system,
            component,
            extensionsByPriority(),
            specialOptions=specialOptions,
            overwrite=overwrite,
            addDefaultOptions=False,
        )
    else:
        result = gComponentInstaller.addDefaultOptionsToCS(
            gConfig,
            cType,
            system,
            component,
            extensionsByPriority(),
            specialOptions=specialOptions,
            overwrite=overwrite,
        )

    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    result = gComponentInstaller.installComponent(cType, system, component,
                                                  extensionsByPriority(),
                                                  module)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    gLogger.notice(
        "Successfully installed component %s in %s system, now setting it up" %
        (component, system))
    result = gComponentInstaller.setupComponent(cType, system, component,
                                                extensionsByPriority(), module)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    if component == "ComponentMonitoring":
        result = MonitoringUtilities.monitorInstallation(
            "DB", system, "InstalledComponentsDB")
        if not result["OK"]:
            gLogger.error(result["Message"])
            DIRACexit(1)
    result = MonitoringUtilities.monitorInstallation(cType, system, component,
                                                     module)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    gLogger.notice("Successfully completed the installation of %s/%s" %
                   (system, component))
    DIRACexit()
  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 )
def main():
    global overwrite
    global specialOptions
    global module
    global specialOptions

    from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller

    gComponentInstaller.exitOnError = True

    Script.registerSwitch("w", "overwrite",
                          "Overwrite the configuration in the global CS",
                          setOverwrite)
    Script.registerSwitch("m:", "module=",
                          "Python module name for the component code",
                          setModule)
    Script.registerSwitch("p:", "parameter=", "Special component option ",
                          setSpecialOption)
    # Registering arguments will automatically add their description to the help menu
    Script.registerArgument((
        "System/Component: Full component name (ie: WorkloadManagement/Matcher)",
        "System:           Name of the DIRAC system (ie: WorkloadManagement)",
    ))
    Script.registerArgument(
        " Component:        Name of the DIRAC service (ie: Matcher)",
        mandatory=False)
    Script.parseCommandLine()
    args = Script.getPositionalArgs()

    if len(args) == 1:
        args = args[0].split("/")

    if len(args) != 2:
        Script.showHelp()
        DIRACexit(1)

    system = args[0]
    component = args[1]

    result = gComponentInstaller.addDefaultOptionsToCS(
        gConfig,
        "service",
        system,
        component,
        extensionsByPriority(),
        specialOptions=specialOptions,
        overwrite=overwrite,
    )

    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)

    result = gComponentInstaller.addTornadoOptionsToCS(gConfig)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)

    result = gComponentInstaller.installTornado()
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)

    gLogger.notice(
        "Successfully installed component %s in %s system, now setting it up" %
        (component, system))
    result = gComponentInstaller.setupTornadoService(system, component,
                                                     extensionsByPriority(),
                                                     module)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)

    result = MonitoringUtilities.monitorInstallation("service", system,
                                                     component, module)
    if not result["OK"]:
        gLogger.error(result["Message"])
        DIRACexit(1)
    gLogger.notice("Successfully completed the installation of %s/%s" %
                   (system, component))
    DIRACexit()
Esempio n. 10
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 )
Esempio n. 11
0
def main():
    global overwrite
    global specialOptions
    global module
    global specialOptions

    from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller
    gComponentInstaller.exitOnError = True

    Script.registerSwitch("w", "overwrite",
                          "Overwrite the configuration in the global CS",
                          setOverwrite)
    Script.registerSwitch("m:", "module=",
                          "Python module name for the component code",
                          setModule)
    Script.registerSwitch("p:", "parameter=", "Special component option ",
                          setSpecialOption)
    Script.parseCommandLine()
    args = Script.getPositionalArgs()

    if len(args) == 1:
        args = args[0].split('/')

    if len(args) != 2:
        Script.showHelp()
        DIRACexit(1)

    system = args[0]
    component = args[1]
    compOrMod = module if module else component

    result = gComponentInstaller.addDefaultOptionsToCS(
        gConfig,
        'service',
        system,
        component,
        getCSExtensions(),
        specialOptions=specialOptions,
        overwrite=overwrite)

    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)

    result = gComponentInstaller.addTornadoOptionsToCS(gConfig)
    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)

    result = gComponentInstaller.installTornado()
    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)

    gLogger.notice(
        'Successfully installed component %s in %s system, now setting it up' %
        (component, system))
    result = gComponentInstaller.setupTornadoService(system, component,
                                                     getCSExtensions(), module)
    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)

    result = MonitoringUtilities.monitorInstallation('service', system,
                                                     component, module)
    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)
    gLogger.notice('Successfully completed the installation of %s/%s' %
                   (system, component))
    DIRACexit()
Esempio n. 12
0
def main():
    global overwrite
    global specialOptions
    global module
    global specialOptions

    from DIRAC.FrameworkSystem.Client.ComponentInstaller import gComponentInstaller
    gComponentInstaller.exitOnError = True

    Script.registerSwitch("w", "overwrite",
                          "Overwrite the configuration in the global CS",
                          setOverwrite)
    Script.registerSwitch("m:", "module=",
                          "Python module name for the component code",
                          setModule)
    Script.registerSwitch("p:", "parameter=", "Special component option ",
                          setSpecialOption)
    Script.parseCommandLine()
    args = Script.getPositionalArgs()

    if len(args) == 1:
        args = args[0].split('/')

    if len(args) != 2:
        Script.showHelp(exitCode=1)

    cType = None
    system = args[0]
    component = args[1]
    compOrMod = module if module else component

    result = gComponentInstaller.getSoftwareComponents(getCSExtensions())
    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)
    else:
        availableComponents = result['Value']

    for compType in availableComponents:
        if system in availableComponents[
                compType] and compOrMod in availableComponents[compType][
                    system]:
            cType = compType[:-1].lower()
            break

    if not cType:
        gLogger.error('Component %s/%s is not available for installation' %
                      (system, component))
        DIRACexit(1)

    if module:
        result = gComponentInstaller.addDefaultOptionsToCS(gConfig,
                                                           cType,
                                                           system,
                                                           module,
                                                           getCSExtensions(),
                                                           overwrite=overwrite)
        result = gComponentInstaller.addDefaultOptionsToCS(
            gConfig,
            cType,
            system,
            component,
            getCSExtensions(),
            specialOptions=specialOptions,
            overwrite=overwrite,
            addDefaultOptions=False)
    else:
        result = gComponentInstaller.addDefaultOptionsToCS(
            gConfig,
            cType,
            system,
            component,
            getCSExtensions(),
            specialOptions=specialOptions,
            overwrite=overwrite)

    if not result['OK']:
        gLogger.error(result['Message'])
        DIRACexit(1)
    else:
        result = gComponentInstaller.installComponent(cType, system, component,
                                                      getCSExtensions(),
                                                      module)
        if not result['OK']:
            gLogger.error(result['Message'])
            DIRACexit(1)
        else:
            gLogger.notice(
                'Successfully installed component %s in %s system, now setting it up'
                % (component, system))
            result = gComponentInstaller.setupComponent(
                cType, system, component, getCSExtensions(), module)
            if not result['OK']:
                gLogger.error(result['Message'])
                DIRACexit(1)
            if component == 'ComponentMonitoring':
                result = MonitoringUtilities.monitorInstallation(
                    'DB', system, 'InstalledComponentsDB')
                if not result['OK']:
                    gLogger.error(result['Message'])
                    DIRACexit(1)
            result = MonitoringUtilities.monitorInstallation(
                cType, system, component, module)
            if not result['OK']:
                gLogger.error(result['Message'])
                DIRACexit(1)
            gLogger.notice('Successfully completed the installation of %s/%s' %
                           (system, component))
            DIRACexit()