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_setupComponent( self, componentType, system, component, componentModule = '' ): """ Setup the specified component for running with the runsvdir daemon It implies installComponent """ result = gComponentInstaller.setupComponent( componentType, system, component, getCSExtensions(), componentModule ) gConfig.forceRefresh() return result
def getStepDefinition(stepName, modulesNameList=None, importLine="""""", parametersList=None): """ Given a name, a list of modules name, and a list of parameters, returns a step definition. Remember that Step definition = Parameters + Module Instances """ if modulesNameList is None: modulesNameList = [] if parametersList is None: parametersList = [] # In case the importLine is not set, this is looking for a DIRAC extension, if any. # The extension is supposed to be called ExtDIRAC. if not importLine: importLine = "DIRAC.Workflow.Modules" for ext in getCSExtensions(): if ext.lower() == getVO(): importLine = ext + "DIRAC.Workflow.Modules" break stepDef = StepDefinition(stepName) for moduleName in modulesNameList: # create the module definition moduleDef = ModuleDefinition(moduleName) try: # Look in the importLine given, or the DIRAC if the given location can't be imported moduleDef.setDescription( getattr( __import__("%s.%s" % (importLine, moduleName), globals(), locals(), ['__doc__']), "__doc__")) moduleDef.setBody("""\nfrom %s.%s import %s\n""" % (importLine, moduleName, moduleName)) except ImportError: alternativeImportLine = "DIRAC.Workflow.Modules" moduleDef.setDescription( getattr( __import__("%s.%s" % (alternativeImportLine, moduleName), globals(), locals(), ['__doc__']), "__doc__")) moduleDef.setBody("""\nfrom %s.%s import %s\n""" % (alternativeImportLine, moduleName, moduleName)) # add the module to the step, and instance it stepDef.addModule(moduleDef) stepDef.createModuleInstance(module_type=moduleName, name=moduleName) # add parameters to the module definition for pName, pType, pValue, pDesc in parametersList: p = Parameter(pName, pValue, pType, "", "", True, False, pDesc) stepDef.addParameter(Parameter(parameter=p)) return stepDef
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_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)
def export_getOverallStatus( self ): """ Get the complete status information for the components in the given list """ result = gComponentInstaller.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 = gComponentInstaller.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_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 getStepDefinition( stepName, modulesNameList = [], importLine = """""", parametersList = [] ): """ Given a name, a list of modules name, and a list of parameters, returns a step definition. Remember that Step definition = Parameters + Module Instances """ # In case the importLine is not set, this is looking for a DIRAC extension, if any. # The extension is supposed to be called ExtDIRAC. if not importLine: importLine = "DIRAC.Workflow.Modules" for ext in getCSExtensions(): if ext.lower() == getVO(): importLine = ext + "DIRAC.Workflow.Modules" break stepDef = StepDefinition( stepName ) for moduleName in modulesNameList: # create the module definition moduleDef = ModuleDefinition( moduleName ) try: # Look in the importLine given, or the DIRAC if the given location can't be imported moduleDef.setDescription( getattr( __import__( "%s.%s" % ( importLine, moduleName ), globals(), locals(), ['__doc__'] ), "__doc__" ) ) moduleDef.setBody( """\nfrom %s.%s import %s\n""" % ( importLine, moduleName, moduleName ) ) except ImportError: alternativeImportLine = "DIRAC.Workflow.Modules" moduleDef.setDescription( getattr( __import__( "%s.%s" % ( alternativeImportLine, moduleName ), globals(), locals(), ['__doc__'] ), "__doc__" ) ) moduleDef.setBody( """\nfrom %s.%s import %s\n""" % ( alternativeImportLine, moduleName, moduleName ) ) # add the module to the step, and instance it stepDef.addModule( moduleDef ) stepDef.createModuleInstance( module_type = moduleName, name = moduleName ) # add parameters to the module definition for pName, pType, pValue, pDesc in parametersList: p = Parameter( pName, pValue, pType, "", "", True, False, pDesc ) stepDef.addParameter( Parameter( parameter = p ) ) return stepDef
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_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_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.0 else: percentage = 0 name = "Memory" if mtype == "Swap": name = "Swap" result[name] = "%.1f%%/%.1fMB" % (percentage, memory / 1024.0) # 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_getInfo( self ): """ Get versions of the installed DIRAC software and extensions, setup of the local installation """ return InstallTools.getInfo( 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_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) cmdList = ['dirac-install', '-r', version, '-t', 'server'] if rootPath: cmdList.extend(['-P', rootPath]) # Check if there are extensions extensionList = getCSExtensions() if extensionList: # by default we do not install WebApp if "WebApp" in extensionList: extensionList.remove("WebApp") webPortal = gConfig.getValue('/LocalInstallation/WebApp', False) if webPortal: if "WebAppDIRAC" not in extensionList: extensionList.append("WebAppDIRAC") cmdList += ['-e', ','.join(extensionList)] project = gConfig.getValue('/LocalInstallation/Project') if project: cmdList += ['-l', project] # 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) return S_OK()
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_addDefaultOptionsToComponentCfg( self, componentType, system, component ): """ Add default component options local component cfg """ return InstallTools.addDefaultOptionsToComponentCfg( componentType, system, component, getCSExtensions() )
def export_getOverallStatus(self): """ Get the complete status information for the components in the given list """ return InstallTools.getOverallStatus(getCSExtensions())
def __readHostInfo(): """ 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 with open( '/proc/loadavg' ) as fd: line = fd.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 with open( '/proc/cpuinfo', 'r' ) as fd: lines = fd.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 = gComponentInstaller.getInfo( getCSExtensions() ) if infoResult['OK']: result.update( infoResult['Value'] ) # the infoResult value is {"Extensions":{'a1':'v1',a2:'v2'}; we convert to a string result.update( {"Extensions":";".join( ["%s:%s" % ( key, value ) for ( key, value ) in infoResult["Value"].get( 'Extensions' ).iteritems()] )} ) # 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'] = resultCert['Value']['groupProperties'] result['CertificateIssuer'] = resultCert['Value']['issuer'] # Host uptime try: with open( '/proc/uptime', 'r' ) as upFile: uptime_seconds = float( upFile.readline().split()[0] ) result['Uptime'] = str( timedelta( seconds = uptime_seconds ) ) except: pass return S_OK(result)
def export_getInfo( self ): """ Get versions of the installed DIRAC software and extensions, setup of the local installation """ return gComponentInstaller.getInfo( getCSExtensions() )
def export_getOverallStatus( self ): """ Get the complete status information for the components in the given list """ return InstallTools.getOverallStatus( getCSExtensions() )
def _updateSoftwarePy2(self, version, rootPath, diracOSVersion): """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) installer = None if not find_executable("dirac-install"): installer = tempfile.NamedTemporaryFile(suffix=".py", mode="wb") with requests.get( "https://raw.githubusercontent.com/DIRACGrid/management/master/dirac-install.py", stream=True) as r: if not r.ok: return S_ERROR( "Failed to download dirac-install from management repo" ) for chunk in r.iter_content(chunk_size=1024**2): installer.write(chunk) installer.flush() self.log.info("Downloaded dirac-install.py py2 installer to", installer.name) cmdList = ["python", installer.name, "-r", version, "-t", "server"] else: cmdList = ["dirac-install", "-r", version, "-t", "server"] if rootPath: cmdList.extend(["-P", rootPath]) # Check if there are extensions extensionList = getCSExtensions() # By default we do not install WebApp if "WebApp" in extensionList or []: extensionList.remove("WebApp") webPortal = gConfig.getValue("/LocalInstallation/WebApp", False) if webPortal and "WebAppDIRAC" not in extensionList: extensionList.append("WebAppDIRAC") cmdList += ["-e", ",".join(extensionList)] project = gConfig.getValue("/LocalInstallation/Project") if project: cmdList += ["-l", project] 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 installer: installer.close() if not result["OK"]: return result status = result["Value"][0] if status == 0: return S_OK() # Get error messages error = [ line.strip() for line in result["Value"][1].split("\n") if "error" in line.lower() ] return S_ERROR("\n".join( error or "Failed to update software to %s" % version))
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_installComponent( self, componentType, system, component, componentModule='' ): """ Install runit directory for the specified component """ return InstallTools.installComponent( componentType, system, component, getCSExtensions(), componentModule )
def export_addDefaultOptionsToComponentCfg(self, componentType, system, component): """ Add default component options local component cfg """ return gComponentInstaller.addDefaultOptionsToComponentCfg( componentType, system, component, getCSExtensions())
def export_getAvailableDatabases( self ): """ Get the list of databases which software is installed in the system """ return InstallTools.getAvailableDatabases( getCSExtensions() )
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_getSoftwareComponents(self): """ Get the list of all the components ( services and agents ) for which the software is installed on the system """ return gComponentInstaller.getSoftwareComponents(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_getAvailableDatabases(self): """ Get the list of databases which software is installed in the system """ return gComponentInstaller.getAvailableDatabases(getCSExtensions())
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_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() if extensionList: # by default we do not install WebApp if "WebApp" in extensionList: extensionList.remove("WebApp") webPortal = gConfig.getValue('/LocalInstallation/WebApp', False) # this is the new portal if webPortal: if "WebAppDIRAC" not in extensionList: extensionList.append("WebAppDIRAC") cmdList += ['-e', ','.join(extensionList)] project = gConfig.getValue('/LocalInstallation/Project') if project: cmdList += ['-l', project] # 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) # 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)) if webPortal: # we have a to compile the new web portal... webappCompileScript = os.path.join( gComponentInstaller.instancePath, 'pro', "WebAppDIRAC/scripts", "dirac-webapp-compile.py") outfile = "%s.out" % webappCompileScript err = "%s.err" % webappCompileScript result = systemCall( False, ['dirac-webapp-compile', ' > ', outfile, ' 2> ', err]) if not result['OK']: return result if result['Value'][0] != 0: error = result['Value'][1].split('\n') error.extend(result['Value'][2].split('\n')) error.append('Failed to compile the java script!') return S_ERROR('\n'.join(error)) return S_OK()
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() )