def export_installMySQL(self, mysqlPassword=None, diracPassword=None):
        """ Install MySQL database server
    """

        if mysqlPassword or diracPassword:
            InstallTools.setMySQLPasswords(mysqlPassword, diracPassword)
        if InstallTools.mysqlInstalled()['OK']:
            return S_OK('Already installed')

        result = InstallTools.installMySQL()
        if not result['OK']:
            return result

        return S_OK('Successfully installed')
  def export_installMySQL( self, mysqlPassword = None, diracPassword = None ):
    """ Install MySQL database server
    """

    if mysqlPassword or diracPassword:
      InstallTools.setMySQLPasswords( mysqlPassword, diracPassword )
    if InstallTools.mysqlInstalled()['OK']:
      return S_OK( 'Already installed' )

    result = InstallTools.installMySQL()
    if not result['OK']:
      return result

    return S_OK( 'Successfully installed' )
 def export_addDatabaseOptionsToCS(self, system, database, overwrite=False):
     """ Add the section with the database options to the CS
 """
     return InstallTools.addDatabaseOptionsToCS(gConfig,
                                                system,
                                                database,
                                                overwrite=overwrite)
 def export_setupComponent( self, componentType, system, component, componentModule='' ):
   """ Setup the specified component for running with the runsvdir daemon
       It implies installComponent
   """
   result = InstallTools.setupComponent( componentType, system, component, getCSExtensions(), componentModule )
   gConfig.forceRefresh()
   return result
示例#5
0
  def do_add( self, args ):
    """
        Add new entity to the Configuration Service

        usage:

          add system <system> <instance>
    """
    argss = args.split()
    option = argss[0]
    del argss[0]
    if option == "instance" or option == "system":
      system = argss[0]
      instance = argss[1]
      client = SystemAdministratorClient( self.host, self.port )
      result = client.getInfo()
      if not result['OK']:
        self.__errMsg( result['Message'] )
      hostSetup = result['Value']['Setup']
      instanceName = gConfig.getValue( '/DIRAC/Setups/%s/%s' % ( hostSetup, system ), '' )
      if instanceName:
        if instanceName == instance:
          print "System %s already has instance %s defined in %s Setup" % ( system, instance, hostSetup )
        else:
          self.__errMsg( "System %s already has instance %s defined in %s Setup" % ( system, instance, hostSetup ) )
        return
      result = InstallTools.addSystemInstance( system, instance, hostSetup )
      if not result['OK']:
        self.__errMsg( result['Message'] )
      else:
        print "%s system instance %s added successfully" % ( system, instance )
    else:
      print "Unknown option:", option
  def do_add( self, args ):
    """
        Add new entity to the Configuration Service

        usage:

          add system <system> <instance>
    """
    argss = args.split()
    option = argss[0]
    del argss[0]
    if option == "instance" or option == "system":
      system = argss[0]
      instance = argss[1]
      client = SystemAdministratorClient( self.host, self.port )
      result = client.getInfo()
      if not result['OK']:
        self.__errMsg( result['Message'] )
      hostSetup = result['Value']['Setup']
      instanceName = gConfig.getValue( '/DIRAC/Setups/%s/%s' % ( hostSetup, system ), '' )
      if instanceName:
        if instanceName == instance:
          print "System %s already has instance %s defined in %s Setup" % ( system, instance, hostSetup )
        else:
          self.__errMsg( "System %s already has instance %s defined in %s Setup" % ( system, instance, hostSetup ) )
        return
      result = InstallTools.addSystemInstance( system, instance, hostSetup )
      if not result['OK']:
        self.__errMsg( result['Message'] )
      else:
        print "%s system instance %s added successfully" % ( system, instance )
    else:
      print "Unknown option:", option
 def export_getOverallStatus( self ):
   """  Get the complete status information for the components in the
        given list
   """
   result = InstallTools.getOverallStatus( getCSExtensions() )
   if not result['OK']:
     return result
   statusDict = result['Value']
   for compType in statusDict:
     for system in statusDict[compType]:
       for component in statusDict[compType][system]:
         result = InstallTools.getComponentModule( gConfig,system,component,compType )
         if not result['OK']:
           statusDict[compType][system][component]['Module'] = "Unknown"
         else:
           statusDict[compType][system][component]['Module'] = result['Value']
   return S_OK(statusDict)   
    def export_checkComponentLog(self, component):
        """ Check component log for errors
    """
        componentList = []
        if '*' in component:
            if component == '*':
                result = InstallTools.getSetupComponents()
                if result['OK']:
                    for ctype in ['Services', 'Agents']:
                        if ctype in result['Value']:
                            for sname in result['Value'][ctype]:
                                for cname in result['Value'][ctype][sname]:
                                    componentList.append('/'.join(
                                        [sname, cname]))
        elif type(component) in StringTypes:
            componentList = [component]
        else:
            componentList = component

        resultDict = {}
        for c in componentList:
            if not '/' in c:
                continue
            system, cname = c.split('/')

            startDir = InstallTools.startDir
            currentLog = startDir + '/' + system + '_' + cname + '/log/current'
            logFile = file(currentLog, 'r')
            logLines = logFile.readlines()
            logFile.close()

            errors_1 = 0
            errors_24 = 0
            now = dateTime()
            lastError = ''
            for line in logLines:
                if "ERROR:" in line:
                    fields = line.split()
                    recent = False
                    timeStamp = fromString(fields[0] + ' ' + fields[1])
                    if (now - timeStamp) < hour:
                        errors_1 += 1
                        recent = True
                    if (now - timeStamp) < day:
                        errors_24 += 1
                        recent = True
                    if recent:
                        lastError = line.split('ERROR:')[-1].strip()

            resultDict[c] = {
                'ErrorsHour': errors_1,
                'ErrorsDay': errors_24,
                'LastError': lastError
            }

        return S_OK(resultDict)
 def export_installComponent(self,
                             componentType,
                             system,
                             component,
                             componentModule=''):
     """ Install runit directory for the specified component
 """
     return InstallTools.installComponent(componentType, system, component,
                                          getCSExtensions(),
                                          componentModule)
 def export_getOverallStatus(self):
     """  Get the complete status information for the components in the
      given list
 """
     result = InstallTools.getOverallStatus(getCSExtensions())
     if not result['OK']:
         return result
     statusDict = result['Value']
     for compType in statusDict:
         for system in statusDict[compType]:
             for component in statusDict[compType][system]:
                 result = InstallTools.getComponentModule(
                     gConfig, system, component, compType)
                 if not result['OK']:
                     statusDict[compType][system][component][
                         'Module'] = "Unknown"
                 else:
                     statusDict[compType][system][component][
                         'Module'] = result['Value']
     return S_OK(statusDict)
 def export_addDefaultOptionsToCS(self,
                                  componentType,
                                  system,
                                  component,
                                  overwrite=False):
     """ Add default component options to the global CS or to the local options
 """
     return InstallTools.addDefaultOptionsToCS(gConfig,
                                               componentType,
                                               system,
                                               component,
                                               getCSExtensions(),
                                               overwrite=overwrite)
 def export_setupComponent(self,
                           componentType,
                           system,
                           component,
                           componentModule=''):
     """ Setup the specified component for running with the runsvdir daemon
     It implies installComponent
 """
     result = InstallTools.setupComponent(componentType, system, component,
                                          getCSExtensions(),
                                          componentModule)
     gConfig.forceRefresh()
     return result
  def export_getComponentDocumentation( self, cType, system, module ):
    if cType == 'service':
      module = '%sHandler' % module

    result = InstallTools.getExtensions()
    extensions = result[ 'Value' ]
    # Look for the component in extensions
    for extension in extensions:
      try:
        importedModule = importlib.import_module( '%s.%sSystem.%s.%s' % ( extension, system, cType.capitalize(), module ) )
        return S_OK( importedModule.__doc__ )
      except Exception, e:
        pass
    def export_checkComponentLog(self, component):
        """ Check component log for errors
    """
        componentList = []
        if "*" in component:
            if component == "*":
                result = InstallTools.getSetupComponents()
                if result["OK"]:
                    for ctype in ["Services", "Agents"]:
                        if ctype in result["Value"]:
                            for sname in result["Value"][ctype]:
                                for cname in result["Value"][ctype][sname]:
                                    componentList.append("/".join([sname, cname]))
        elif type(component) in StringTypes:
            componentList = [component]
        else:
            componentList = component

        resultDict = {}
        for c in componentList:
            if not "/" in c:
                continue
            system, cname = c.split("/")

            startDir = InstallTools.startDir
            currentLog = startDir + "/" + system + "_" + cname + "/log/current"
            logFile = file(currentLog, "r")
            logLines = logFile.readlines()
            logFile.close()

            errors_1 = 0
            errors_24 = 0
            now = dateTime()
            lastError = ""
            for line in logLines:
                if "ERROR:" in line:
                    fields = line.split()
                    recent = False
                    timeStamp = fromString(fields[0] + " " + fields[1])
                    if (now - timeStamp) < hour:
                        errors_1 += 1
                        recent = True
                    if (now - timeStamp) < day:
                        errors_24 += 1
                        recent = True
                    if recent:
                        lastError = line.split("ERROR:")[-1].strip()

            resultDict[c] = {"ErrorsHour": errors_1, "ErrorsDay": errors_24, "LastError": lastError}

        return S_OK(resultDict)
  def export_checkComponentLog( self, component ):
    """ Check component log for errors
    """
    componentList = []
    if '*' in component:
      if component == '*':
        result = InstallTools.getSetupComponents()
        if result['OK']:
          for ctype in ['Services', 'Agents']:
            if ctype in result['Value']:
              for sname in result['Value'][ctype]:
                for cname in result['Value'][ctype][sname]:
                  componentList.append( '/'.join( [sname, cname] ) )
    elif type( component ) in StringTypes:
      componentList = [component]
    else:
      componentList = component

    resultDict = {}
    for c in componentList:
      if not '/' in c:
        continue
      system, cname = c.split( '/' )

      startDir = InstallTools.startDir
      currentLog = startDir + '/' + system + '_' + cname + '/log/current'
      logFile = file( currentLog, 'r' )
      logLines = logFile.readlines()
      logFile.close()

      errors_1 = 0
      errors_24 = 0
      now = dateTime()
      lastError = ''
      for line in logLines:
        if "ERROR:" in line:
          fields = line.split()
          recent = False
          timeStamp = fromString( fields[0] + ' ' + fields[1] )
          if ( now - timeStamp ) < hour:
            errors_1 += 1
            recent = True
          if ( now - timeStamp ) < day:
            errors_24 += 1
            recent = True
          if recent:
            lastError = line.split( 'ERROR:' )[-1].strip()

      resultDict[c] = {'ErrorsHour':errors_1, 'ErrorsDay':errors_24, 'LastError':lastError}

    return S_OK( resultDict )
    def export_getComponentDocumentation(self, cType, system, module):
        if cType == 'service':
            module = '%sHandler' % module

        result = InstallTools.getExtensions()
        extensions = result['Value']
        # Look for the component in extensions
        for extension in extensions:
            try:
                importedModule = importlib.import_module(
                    '%s.%sSystem.%s.%s' %
                    (extension, system, cType.capitalize(), module))
                return S_OK(importedModule.__doc__)
            except Exception, e:
                pass
示例#17
0
def portalVersion( rootPath ):

  from DIRAC.Core.Utilities import InstallTools
  from DIRAC.ConfigurationSystem.Client.Helpers.CSGlobals import getCSExtensions

  result = InstallTools.getInfo( getCSExtensions() )

  if not result[ "OK" ]:
    return getRelease( rootPath )
  version = result[ "Value" ]

  if not "Extensions" in version:
    return getRelease( rootPath )
  extensions = version[ "Extensions" ]

  if not "DIRACWeb" in extensions:
    return getRelease( rootPath )
  return extensions[ "DIRACWeb" ]
示例#18
0
def portalVersion(rootPath):

    from DIRAC.Core.Utilities import InstallTools
    from DIRAC.ConfigurationSystem.Client.Helpers.CSGlobals import getCSExtensions

    result = InstallTools.getInfo(getCSExtensions())

    if not result["OK"]:
        return getRelease(rootPath)
    version = result["Value"]

    if not "Extensions" in version:
        return getRelease(rootPath)
    extensions = version["Extensions"]

    if not "DIRACWeb" in extensions:
        return getRelease(rootPath)
    return extensions["DIRACWeb"]
示例#19
0
def getVersion():
  result = InstallTools.getInfo( getCSExtensions() )
  if not result[ "OK" ]:
    return ""

  dirac = ""
  values = result[ "Value" ]
  if "DIRAC" in values:
    dirac = "DIRAC: %s" % str( values[ "DIRAC" ] )

  if "Extensions" in values:
    ext = values[ "Extensions" ]
    if not len( ext ) > 0:
      return dirac
    extResult = list()
    for i in ext:
      extResult.append( "%s: %s" % ( i , ext[ i ] ) )
    ext = ", ".join( extResult )
    version = "%s, %s" % ( dirac , ext )
  return version
 def export_getSetupComponents( self ):
   """  Get the list of all the components ( services and agents )
        set up for running with runsvdir in /opt/dirac/startup directory
   """
   return InstallTools.getSetupComponents()
    def export_updateSoftware(self, version, rootPath="", gridVersion=""):
        """ Update the local DIRAC software installation to version
    """

        # Check that we have a sane local configuration
        result = gConfig.getOptionsDict('/LocalInstallation')
        if not result['OK']:
            return S_ERROR(
                'Invalid installation - missing /LocalInstallation section in the configuration'
            )
        elif not result['Value']:
            return S_ERROR(
                'Invalid installation - empty /LocalInstallation section in the configuration'
            )

        if rootPath and not os.path.exists(rootPath):
            return S_ERROR('Path "%s" does not exists' % rootPath)
        # For LHCb we need to check Oracle client
        installOracleClient = False
        oracleFlag = gConfig.getValue('/LocalInstallation/InstallOracleClient',
                                      'unknown')
        if oracleFlag.lower() in ['yes', 'true', '1']:
            installOracleClient = True
        elif oracleFlag.lower() == "unknown":
            result = systemCall(0, ['python', '-c', 'import cx_Oracle'])
            if result['OK'] and result['Value'][0] == 0:
                installOracleClient = True

        cmdList = ['dirac-install', '-r', version, '-t', 'server']
        if rootPath:
            cmdList.extend(['-P', rootPath])

        # Check if there are extensions
        extensionList = getCSExtensions()
        webFlag = gConfig.getValue('/LocalInstallation/WebPortal', False)
        if webFlag:
            extensionList.append('Web')
        if extensionList:
            cmdList += ['-e', ','.join(extensionList)]

        # Are grid middleware bindings required ?
        if gridVersion:
            cmdList.extend(['-g', gridVersion])

        targetPath = gConfig.getValue(
            '/LocalInstallation/TargetPath',
            gConfig.getValue('/LocalInstallation/RootPath', ''))
        if targetPath and os.path.exists(targetPath + '/etc/dirac.cfg'):
            cmdList.append(targetPath + '/etc/dirac.cfg')
        else:
            return S_ERROR('Local configuration not found')

        result = systemCall(0, cmdList)
        if not result['OK']:
            return result
        status = result['Value'][0]
        if status != 0:
            # Get error messages
            error = []
            output = result['Value'][1].split('\n')
            for line in output:
                line = line.strip()
                if 'error' in line.lower():
                    error.append(line)
            if error:
                message = '\n'.join(error)
            else:
                message = "Failed to update software to %s" % version
            return S_ERROR(message)

        # Check if there is a MySQL installation and fix the server scripts if necessary
        if os.path.exists(InstallTools.mysqlDir):
            startupScript = os.path.join(InstallTools.instancePath, 'mysql',
                                         'share', 'mysql', 'mysql.server')
            if not os.path.exists(startupScript):
                startupScript = os.path.join(InstallTools.instancePath, 'pro',
                                             'mysql', 'share', 'mysql',
                                             'mysql.server')
            if os.path.exists(startupScript):
                InstallTools.fixMySQLScripts(startupScript)

        # For LHCb we need to check Oracle client
        if installOracleClient:
            result = systemCall(0, 'install_oracle-client.sh')
            if not result['OK']:
                return result
            status = result['Value'][0]
            if status != 0:
                # Get error messages
                error = result['Value'][1].split('\n')
                error.extend(result['Value'][2].split('\n'))
                error.append('Failed to install Oracle client module')
                return S_ERROR('\n'.join(error))
        return S_OK()
 def export_getInfo( self ):
   """  Get versions of the installed DIRAC software and extensions, setup of the
        local installation
   """
   return InstallTools.getInfo( getCSExtensions() )
 def export_addDefaultOptionsToCS( self, componentType, system, component, overwrite = False ):
   """ Add default component options to the global CS or to the local options
   """
   return InstallTools.addDefaultOptionsToCS( gConfig, componentType, system, component,
                                              getCSExtensions(),
                                              overwrite = overwrite )
 def export_installDatabase( self, dbName, mysqlPassword = None ):
   """ Install a DIRAC database named dbName
   """
   if mysqlPassword :
     InstallTools.setMySQLPasswords( mysqlPassword )
   return InstallTools.installDatabase( dbName )
 def export_getAvailableDatabases( self ):
   """ Get the list of databases which software is installed in the system
   """
   return InstallTools.getAvailableDatabases( getCSExtensions() )
 def export_getMySQLStatus( self ):
   """ Get the status of the MySQL database installation
   """
   return InstallTools.getMySQLStatus()
 def export_getStartupComponentStatus( self, componentTupleList ):
   """  Get the list of all the components ( services and agents )
        set up for running with runsvdir in startup directory
   """
   return InstallTools.getStartupComponentStatus( componentTupleList )
 def export_setupComponent(self, componentType, system, component):
     """ Setup the specified component for running with the runsvdir daemon
     It implies installComponent
 """
     return InstallTools.setupComponent(componentType, system, component,
                                        getCSExtensions())
 def export_getStartupComponentStatus(self, componentTupleList):
     """  Get the list of all the components ( services and agents )
      set up for running with runsvdir in startup directory
 """
     return InstallTools.getStartupComponentStatus(componentTupleList)
 def export_getOverallStatus(self):
     """  Get the complete status information for the components in the
      given list
 """
     return InstallTools.getOverallStatus(getCSExtensions())
 def export_getSetupComponents(self):
     """  Get the list of all the components ( services and agents )
      set up for running with runsvdir in /opt/dirac/startup directory
 """
     return InstallTools.getSetupComponents()
 def export_getInstalledComponents(self):
     """  Get the list of all the components ( services and agents )
      installed on the system in the runit directory
 """
     return InstallTools.getInstalledComponents()
 def export_addOptionToDiracCfg(self, option, value):
     """ Set option in the local configuration file
 """
     return InstallTools.addOptionToDiracCfg(option, value)
 def export_getLogTail( self, system, component, length = 100 ):
   """ Get the tail of the component log file
   """
   return InstallTools.getLogTail( system, component, length )
 def export_installDatabase(self, dbName, mysqlPassword=None):
     """ Install a DIRAC database named dbName
 """
     if mysqlPassword:
         InstallTools.setMySQLPasswords(mysqlPassword)
     return InstallTools.installDatabase(dbName)
 def export_getDatabases( self, mysqlPassword = None ):
   """ Get the list of installed databases
   """
   if mysqlPassword :
     InstallTools.setMySQLPasswords( mysqlPassword )
   return InstallTools.getDatabases()
 def export_unsetupComponent( self, system, component ):
   """ Removed the specified component from running with the runsvdir daemon
   """
   return InstallTools.unsetupComponent( system, component )
    def do_show(self, args):
        """
        Show list of components with various related information

        usage:

          show software      - show components for which software is available
          show installed     - show components installed in the host with runit system
          show setup         - show components set up for automatic running in the host
          show project       - show project to install or upgrade
          show status        - show status of the installed components
          show database      - show status of the databases
          show mysql         - show status of the MySQL server
          show log  <system> <service|agent> [nlines]
                             - show last <nlines> lines in the component log file
          show info          - show version of software and setup
          show host          - show host related parameters
          show errors [*|<system> <service|agent>]
                             - show error count for the given component or all the components
                               in the last hour and day
    """

        argss = args.split()
        if not argss:
            print self.do_show.__doc__
            return

        option = argss[0]
        del argss[0]

        if option == 'software':
            client = SystemAdministratorClient(self.host, self.port)
            result = client.getSoftwareComponents()
            if not result['OK']:
                self.__errMsg(result['Message'])
            else:
                print
                pprint.pprint(result['Value'])
        elif option == 'installed':
            client = SystemAdministratorClient(self.host, self.port)
            result = client.getInstalledComponents()
            if not result['OK']:
                self.__errMsg(result['Message'])
            else:
                print
                pprint.pprint(result['Value'])
        elif option == 'setup':
            client = SystemAdministratorClient(self.host, self.port)
            result = client.getSetupComponents()
            if not result['OK']:
                self.__errMsg(result['Message'])
            else:
                print
                pprint.pprint(result['Value'])
        elif option == 'project':
            result = SystemAdministratorClient(self.host,
                                               self.port).getProject()
            if not result['OK']:
                self.__errMsg(result['Message'])
            else:
                print "Current project is %s" % result['Value']
        elif option == 'status':
            client = SystemAdministratorClient(self.host, self.port)
            result = client.getOverallStatus()
            if not result['OK']:
                self.__errMsg(result['Message'])
            else:
                fields = [
                    "System", 'Name', 'Module', 'Type', 'Setup', 'Installed',
                    'Runit', 'Uptime', 'PID'
                ]
                records = []
                rDict = result['Value']
                for compType in rDict:
                    for system in rDict[compType]:
                        components = rDict[compType][system].keys()
                        components.sort()
                        for component in components:
                            record = []
                            if rDict[compType][system][component]['Installed']:
                                module = str(rDict[compType][system][component]
                                             ['Module'])
                                record += [
                                    system, component, module,
                                    compType.lower()[:-1]
                                ]
                                if rDict[compType][system][component]['Setup']:
                                    record += ['Setup']
                                else:
                                    record += ['NotSetup']
                                if rDict[compType][system][component][
                                        'Installed']:
                                    record += ['Installed']
                                else:
                                    record += ['NotInstalled']
                                record += [
                                    str(rDict[compType][system][component]
                                        ['RunitStatus'])
                                ]
                                record += [
                                    str(rDict[compType][system][component]
                                        ['Timeup'])
                                ]
                                record += [
                                    str(rDict[compType][system][component]
                                        ['PID'])
                                ]
                                records.append(record)
                printTable(fields, records)
        elif option == 'database' or option == 'databases':
            client = SystemAdministratorClient(self.host, self.port)
            if not InstallTools.mysqlPassword:
                InstallTools.mysqlPassword = "******"
            InstallTools.getMySQLPasswords()
            result = client.getDatabases(InstallTools.mysqlRootPwd)
            if not result['OK']:
                self.__errMsg(result['Message'])
                return
            resultSW = client.getAvailableDatabases()
            if not resultSW['OK']:
                self.__errMsg(resultSW['Message'])
                return

            sw = resultSW['Value']
            installed = result['Value']
            print
            for db in sw:
                if db in installed:
                    print db.rjust(25), ': Installed'
                else:
                    print db.rjust(25), ': Not installed'
            if not sw:
                print "No database found"
        elif option == 'mysql':
            client = SystemAdministratorClient(self.host, self.port)
            result = client.getMySQLStatus()
            if not result['OK']:
                self.__errMsg(result['Message'])
            elif result['Value']:
                print
                for par, value in result['Value'].items():
                    print par.rjust(28), ':', value
            else:
                print "No MySQL database found"
        elif option == "log":
            self.getLog(argss)
        elif option == "info":
            client = SystemAdministratorClient(self.host, self.port)
            result = client.getInfo()
            if not result['OK']:
                self.__errMsg(result['Message'])
            else:
                print
                print "Setup:", result['Value']['Setup']
                print "DIRAC version:", result['Value']['DIRAC']
                if result['Value']['Extensions']:
                    for e, v in result['Value']['Extensions'].items():
                        print "%s version" % e, v
                print
        elif option == "host":
            client = SystemAdministratorClient(self.host, self.port)
            result = client.getHostInfo()
            if not result['OK']:
                self.__errMsg(result['Message'])
            else:
                print
                print "Host info:"
                print

                fields = ['Parameter', 'Value']
                records = []
                for key, value in result['Value'].items():
                    records.append([key, str(value)])

                printTable(fields, records)

        elif option == "errors":
            self.getErrors(argss)
        else:
            print "Unknown option:", option
 def export_getAvailableDatabases(self):
     """ Get the list of databases which software is installed in the system
 """
     return InstallTools.getAvailableDatabases(getCSExtensions())
 def export_addDatabaseOptionsToCS( self, system, database, overwrite = False ):
   """ Add the section with the database options to the CS
   """
   return InstallTools.addDatabaseOptionsToCS( gConfig, system, database, overwrite = overwrite )
 def export_addOptionToDiracCfg( self, option, value ):
   """ Set option in the local configuration file
   """
   return InstallTools.addOptionToDiracCfg( option, value )
  def export_updateSoftware( self, version, rootPath = "", gridVersion = "" ):
    """ Update the local DIRAC software installation to version
    """

    # Check that we have a sane local configuration
    result = gConfig.getOptionsDict( '/LocalInstallation' )
    if not result['OK']:
      return S_ERROR( 'Invalid installation - missing /LocalInstallation section in the configuration' )
    elif not result['Value']:
      return S_ERROR( 'Invalid installation - empty /LocalInstallation section in the configuration' )

    if rootPath and not os.path.exists( rootPath ):
      return S_ERROR( 'Path "%s" does not exists' % rootPath )
    # For LHCb we need to check Oracle client
    installOracleClient = False
    oracleFlag = gConfig.getValue( '/LocalInstallation/InstallOracleClient', 'unknown' )
    if oracleFlag.lower() in ['yes', 'true', '1']:
      installOracleClient = True
    elif oracleFlag.lower() == "unknown":
      result = systemCall( 30, ['python', '-c', 'import cx_Oracle'] )
      if result['OK'] and result['Value'][0] == 0:
        installOracleClient = True

    cmdList = ['dirac-install', '-r', version, '-t', 'server']
    if rootPath:
      cmdList.extend( ['-P', rootPath] )

    # Check if there are extensions
    extensionList = getCSExtensions()
    webFlag = gConfig.getValue( '/LocalInstallation/WebPortal', False )
    if webFlag:
      extensionList.append( 'Web' )
    if extensionList:
      cmdList += ['-e', ','.join( extensionList )]

    # Are grid middleware bindings required ?
    if gridVersion:
      cmdList.extend( ['-g', gridVersion] )

    targetPath = gConfig.getValue( '/LocalInstallation/TargetPath',
                                  gConfig.getValue( '/LocalInstallation/RootPath', '' ) )
    if targetPath and os.path.exists( targetPath + '/etc/dirac.cfg' ):
      cmdList.append( targetPath + '/etc/dirac.cfg' )
    else:
      return S_ERROR( 'Local configuration not found' )

    result = systemCall( 240, cmdList )
    if not result['OK']:
      return result
    status = result['Value'][0]
    if status != 0:
      # Get error messages
      error = []
      output = result['Value'][1].split( '\n' )
      for line in output:
        line = line.strip()
        if 'error' in line.lower():
          error.append( line )
      if error:
        message = '\n'.join( error )
      else:
        message = "Failed to update software to %s" % version
      return S_ERROR( message )

    # Check if there is a MySQL installation and fix the server scripts if necessary
    if os.path.exists( InstallTools.mysqlDir ):
      startupScript = os.path.join( InstallTools.instancePath,
                                    'mysql', 'share', 'mysql', 'mysql.server' )
      if not os.path.exists( startupScript ):
        startupScript = os.path.join( InstallTools.instancePath, 'pro',
                                     'mysql', 'share', 'mysql', 'mysql.server' )
      if os.path.exists( startupScript ):
        InstallTools.fixMySQLScripts( startupScript )

    # For LHCb we need to check Oracle client
    if installOracleClient:
      result = systemCall( 30, 'install_oracle-client.sh' )
      if not result['OK']:
        return result
      status = result['Value'][0]
      if status != 0:
        # Get error messages
        error = result['Value'][1].split( '\n' )
        error.extend( result['Value'][2].split( '\n' ) )
        error.append( 'Failed to install Oracle client module' )
        return S_ERROR( '\n'.join( error ) )
    return S_OK()
 def export_getInstalledComponents( self ):
   """  Get the list of all the components ( services and agents )
        installed on the system in the runit directory
   """
   return InstallTools.getInstalledComponents()
 def export_getSoftwareComponents( self ):
   """  Get the list of all the components ( services and agents ) for which the software
        is installed on the system
   """
   return InstallTools.getSoftwareComponents( getCSExtensions() )
 def export_getSoftwareComponents(self):
     """  Get the list of all the components ( services and agents ) for which the software
      is installed on the system
 """
     return InstallTools.getSoftwareComponents(getCSExtensions())
 def export_getDatabases(self, mysqlPassword=None):
     """ Get the list of installed databases
 """
     if mysqlPassword:
         InstallTools.setMySQLPasswords(mysqlPassword)
     return InstallTools.getDatabases()
 def export_restartComponent( self, system, component ):
   """ Restart the specified component, running with the runsv daemon
   """
   return InstallTools.runsvctrlComponent( system, component, 't' )
  def export_getHostInfo(self):
    """ Get host current loads, memory, etc
    """

    result = dict()
    # Memory info
    re_parser = re.compile(r'^(?P<key>\S*):\s*(?P<value>\d*)\s*kB' )
    for line in open('/proc/meminfo'):
      match = re_parser.match(line)
      if not match:
        continue
      key, value = match.groups(['key', 'value'])
      result[key] = int(value)

    for mtype in ['Mem','Swap']:
      memory = int(result.get(mtype+'Total'))
      mfree = int(result.get(mtype+'Free'))
      if memory > 0:
        percentage = float(memory-mfree)/float(memory)*100.
      else:
        percentage = 0
      name = 'Memory'
      if mtype == "Swap":
        name = 'Swap'
      result[name] = '%.1f%%/%.1fMB' % (percentage,memory/1024.)

    # Loads
    line = open('/proc/loadavg').read()
    l1,l5,l15,d1,d2 = line.split()
    result['Load1'] = l1
    result['Load5'] = l5
    result['Load15'] = l15
    result['Load'] = '/'.join([l1,l5,l15])
    
    # CPU info
    lines = open( '/proc/cpuinfo', 'r' ).readlines()
    processors = 0
    physCores = {}
    for line in lines:
      if line.strip():
        parameter, value = line.split(':')
        parameter = parameter.strip()
        value = value.strip()
        if parameter.startswith('processor'):
          processors += 1
        if parameter.startswith('physical id'):
          physCores[value] = parameter
        if parameter.startswith('model name'):
          result['CPUModel'] = value
        if parameter.startswith('cpu MHz'):     
          result['CPUClock'] = value
    result['Cores'] = processors
    result['PhysicalCores'] = len(physCores)      

    # Disk occupancy
    summary = ''
    status,output = commands.getstatusoutput('df')
    lines = output.split('\n')
    for i in range( len( lines ) ):
      if lines[i].startswith('/dev'):
        fields = lines[i].split()
        if len( fields ) == 1:
          fields += lines[i+1].split()
        disk = fields[0].replace('/dev/sd','')
        partition = fields[5]
        occupancy = fields[4]
        summary += ",%s:%s" % (partition,occupancy)
    result['DiskOccupancy'] = summary[1:]
    result['RootDiskSpace'] = Os.getDiskSpace( DIRAC.rootPath )
    
    # Open files
    puser= getpass.getuser()
    status,output = commands.getstatusoutput('lsof')
    pipes = 0
    files = 0
    sockets = 0
    lines = output.split('\n')
    for line in lines:
      fType = line.split()[4]
      user = line.split()[2]
      if user == puser:
        if fType in ['REG']:
          files += 1
        elif fType in ['unix','IPv4']:
          sockets += 1
        elif fType in ['FIFO']:
          pipes += 1
    result['OpenSockets'] = sockets
    result['OpenFiles'] = files
    result['OpenPipes'] = pipes
    
    infoResult = InstallTools.getInfo( getCSExtensions() )
    if infoResult['OK']:
      result.update( infoResult['Value'] )

    # Host certificate properties
    certFile,keyFile = getHostCertificateAndKeyLocation()
    chain = X509Chain()
    chain.loadChainFromFile( certFile )
    resultCert = chain.getCredentials()
    if resultCert['OK']:
      result['SecondsLeft'] = resultCert['Value']['secondsLeft']
      result['CertificateValidity'] = str( timedelta( seconds = resultCert['Value']['secondsLeft'] ) )
      result['CertificateDN'] = resultCert['Value']['subject']
      result['HostProperties'] = ','.join( resultCert['Value']['groupProperties'] )
      result['CertificateIssuer'] = resultCert['Value']['issuer']

    # Host uptime
    try:
      upFile = open('/proc/uptime', 'r')
      uptime_seconds = float(upFile.readline().split()[0])
      upFile.close()
      result['Uptime'] = str(timedelta(seconds = uptime_seconds))
    except:
      pass

    return S_OK(result)
 def export_stopComponent( self, system, component ):
   """ Stop the specified component, running with the runsv daemon
   """
   return InstallTools.runsvctrlComponent( system, component, 'd' )
 def export_addDefaultOptionsToComponentCfg(self, componentType, system,
                                            component):
     """ Add default component options local component cfg
 """
     return InstallTools.addDefaultOptionsToComponentCfg(
         componentType, system, component, getCSExtensions())
 def export_getInfo(self):
     """  Get versions of the installed DIRAC software and extensions, setup of the
      local installation
 """
     return InstallTools.getInfo(getCSExtensions())
 def export_installComponent( self, componentType, system, component, componentModule='' ):
   """ Install runit directory for the specified component
   """
   return InstallTools.installComponent( componentType, system, component, getCSExtensions(), componentModule )
示例#53
0
    '  System:  Name of the DIRAC system (ie: WorkloadManagement)',
    '  Agent:   Name of the DIRAC agent (ie: JobCleaningAgent)'
]))
Script.parseCommandLine()
args = Script.getPositionalArgs()
if len(args) == 1:
    args = args[0].split('/')

if len(args) != 2:
    Script.showHelp()
    exit(-1)
#
system = args[0]
agent = args[1]

result = InstallTools.addDefaultOptionsToCS(gConfig,
                                            'agent',
                                            system,
                                            agent,
                                            getCSExtensions(),
                                            overwrite=overwrite)
if not result['OK']:
    print "ERROR:", result['Message']
else:
    result = InstallTools.installComponent('agent', system, agent,
                                           getCSExtensions())
    if not result['OK']:
        print "ERROR:", result['Message']
    else:
        print "Successfully installed agent %s in %s system" % (agent, system)
 def export_addDefaultOptionsToComponentCfg( self, componentType, system, component ):
   """ Add default component options local component cfg
   """
   return InstallTools.addDefaultOptionsToComponentCfg( componentType, system, component, getCSExtensions() )
示例#55
0
#!/usr/bin/env python
########################################################################
# $HeadURL$
# File :    dirac-install-mysql
# Author :  Ricardo Graciani
########################################################################
"""
Do the initial installation and configuration of the DIRAC MySQL server
"""
__RCSID__ = "$Id$"

from DIRAC.Core.Base import Script

Script.setUsageMessage('\n'.join([__doc__.split('\n')[1]]))

Script.parseCommandLine()

#
from DIRAC.Core.Utilities import InstallTools
#
InstallTools.exitOnError = True
#
InstallTools.getMySQLPasswords()
#
InstallTools.installMySQL()
#
InstallTools._addMySQLToDiracCfg()
示例#56
0
                                    '  Agent:   Name of the DIRAC agent (ie: JobCleaningAgent)'] ) )
Script.parseCommandLine()
args = Script.getPositionalArgs()
if len( args ) == 1:
  args = args[0].split( '/' )

if len( args ) != 2:
  Script.showHelp()
  DIRACexit( -1 )
#
system = args[0]
agent = args[1]

if module:
  result = InstallTools.addDefaultOptionsToCS( gConfig, 'agent', system, module,
                                               getCSExtensions(),
                                               overwrite = overwrite )
  result = InstallTools.addDefaultOptionsToCS( gConfig, 'agent', system, agent,
                                               getCSExtensions(),
                                               specialOptions=specialOptions,
                                               overwrite = overwrite,
                                               addDefaultOptions = False )
else:
  result = InstallTools.addDefaultOptionsToCS( gConfig, 'agent', system, agent,
                                               getCSExtensions(),
                                               specialOptions=specialOptions,
                                               overwrite = overwrite )
if not result['OK']:
  print "ERROR:", result['Message']
else:
  result = InstallTools.installComponent( 'agent', system, agent, getCSExtensions(), module )
    def do_install(self, args):
        """ 
        Install various DIRAC components 
    
        usage:
        
          install mysql
          install db <database>
          install service <system> <service>
          install agent <system> <agent>
    """
        argss = args.split()
        if not argss:
            print self.do_install.__doc__
            return

        option = argss[0]
        del argss[0]
        if option == "mysql":
            print "Installing MySQL database, this can take a while ..."
            client = SystemAdministratorClient(self.host, self.port)
            if InstallTools.mysqlPassword == 'LocalConfig':
                InstallTools.mysqlPassword = ''
            InstallTools.getMySQLPasswords()
            result = client.installMySQL(InstallTools.mysqlRootPwd,
                                         InstallTools.mysqlPassword)
            if not result['OK']:
                self.__errMsg(result['Message'])
            else:
                print "MySQL:", result['Value']
                print "You might need to restart SystemAdministrator service to take new settings into account"
        elif option == "db":
            if not argss:
                print 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 InstallTools.mysqlPassword:
                InstallTools.mysqlPassword = '******'
            InstallTools.getMySQLPasswords()
            result = client.installDatabase(database,
                                            InstallTools.mysqlRootPwd)
            if not result['OK']:
                self.__errMsg(result['Message'])
                return
            extension, system = result['Value']
            # result = client.addDatabaseOptionsToCS( system, database )
            InstallTools.mysqlHost = self.host
            result = client.getInfo()
            if not result['OK']:
                self.__errMsg(result['Message'])
            hostSetup = result['Value']['Setup']
            result = InstallTools.addDatabaseOptionsToCS(
                gConfig, system, database, hostSetup)
            if not result['OK']:
                self.__errMsg(result['Message'])
                return
            print "Database %s from %s/%s installed successfully" % (
                database, extension, system)
        elif option == "service" or option == "agent":
            if len(argss) < 2:
                print self.do_install.__doc__
                return

            system = argss[0]
            component = argss[1]
            client = SystemAdministratorClient(self.host, self.port)
            # First need to update the CS
            # result = client.addDefaultOptionsToCS( option, system, component )
            InstallTools.host = self.host
            result = client.getInfo()
            if not result['OK']:
                self.__errMsg(result['Message'])
                return
            hostSetup = result['Value']['Setup']
            result = InstallTools.addDefaultOptionsToCS(
                gConfig, option, system, component, getCSExtensions(),
                hostSetup)
            if not result['OK']:
                self.__errMsg(result['Message'])
                return
            # Then we can install and start the component
            result = client.setupComponent(option, system, component)
            if not result['OK']:
                self.__errMsg(result['Message'])
                return
            compType = result['Value']['ComponentType']
            runit = result['Value']['RunitStatus']
            print "%s %s_%s is installed, runit status: %s" % (
                compType, system, component, runit)
        else:
            print "Unknown option:", option
    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:
            print self.do_install.__doc__
            return

        option = argss[0]
        del argss[0]
        if option == "mysql":
            print "Installing MySQL database, this can take a while ..."
            client = SystemAdministratorClient(self.host, self.port)
            if InstallTools.mysqlPassword == 'LocalConfig':
                InstallTools.mysqlPassword = ''
            InstallTools.getMySQLPasswords()
            result = client.installMySQL(InstallTools.mysqlRootPwd,
                                         InstallTools.mysqlPassword)
            if not result['OK']:
                self.__errMsg(result['Message'])
            else:
                print "MySQL:", result['Value']
                print "You might need to restart SystemAdministrator service to take new settings into account"
        elif option == "db":
            if not argss:
                print 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 InstallTools.mysqlPassword:
                InstallTools.mysqlPassword = '******'
            InstallTools.getMySQLPasswords()
            result = client.installDatabase(database,
                                            InstallTools.mysqlRootPwd)
            if not result['OK']:
                self.__errMsg(result['Message'])
                return
            extension, system = result['Value']
            # result = client.addDatabaseOptionsToCS( system, database )
            InstallTools.mysqlHost = self.host
            result = client.getInfo()
            if not result['OK']:
                self.__errMsg(result['Message'])
            hostSetup = result['Value']['Setup']
            result = InstallTools.addDatabaseOptionsToCS(
                gConfig, system, database, hostSetup)
            if not result['OK']:
                self.__errMsg(result['Message'])
                return
            print "Database %s from %s/%s installed successfully" % (
                database, extension, system)
        elif option in ["service", "agent", "executor"]:
            if len(argss) < 2:
                print 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 )
            InstallTools.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 = InstallTools.addDefaultOptionsToCS(
                    gConfig, option, system, module, getCSExtensions(),
                    hostSetup)
                # Add component section with specific parameters only
                result = InstallTools.addDefaultOptionsToCS(
                    gConfig,
                    option,
                    system,
                    component,
                    getCSExtensions(),
                    hostSetup,
                    specialOptions,
                    addDefaultOptions=False)
            else:
                # Install component section
                result = InstallTools.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']
            print "%s %s_%s is installed, runit status: %s" % (
                compType, system, component, runit)
        else:
            print "Unknown option:", option
args = Script.getPositionalArgs()

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

if len(args) != 2:
    Script.showHelp()
    DIRACexit(-1)
#
system = args[0]
executor = args[1]

if module:
    result = InstallTools.addDefaultOptionsToCS(gConfig,
                                                'executor',
                                                system,
                                                module,
                                                getCSExtensions(),
                                                overwrite=overwrite)
    result = InstallTools.addDefaultOptionsToCS(gConfig,
                                                'executor',
                                                system,
                                                executor,
                                                getCSExtensions(),
                                                specialOptions=specialOptions,
                                                overwrite=overwrite,
                                                addDefaultOptions=False)
else:
    result = InstallTools.addDefaultOptionsToCS(gConfig,
                                                'executor',
                                                system,
                                                executor,