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
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
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 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_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
#!/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()
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 doc <type> <system> <name> - show documentation for a given service or agent show host - show host related parameters show hosts - show all available hosts show installations [ list | current | -n <Name> | -h <Host> | -s <System> | -m <Module> | -t <Type> | -itb <InstallationTime before> | -ita <InstallationTime after> | -utb <UnInstallationTime before> | -uta <UnInstallationTime after> ]* - show all the installations of components that match the given 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: gLogger.notice( 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: gLogger.notice( '' ) 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: gLogger.notice( '' ) 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: gLogger.notice( '' ) pprint.pprint( result['Value'] ) elif option == 'project': result = SystemAdministratorClient( self.host, self.port ).getProject() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( "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'] gLogger.notice( '' ) for db in sw: if db in installed: gLogger.notice( db.rjust( 25 ), ': Installed' ) else: gLogger.notice( db.rjust( 25 ), ': Not installed' ) if not sw: gLogger.notice( "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']: gLogger.notice( '' ) for par, value in result['Value'].items(): gLogger.notice( ( par.rjust( 28 ), ':', value ) ) else: gLogger.notice( "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: gLogger.notice( '' ) gLogger.notice( "Setup:", result['Value']['Setup'] ) gLogger.notice( "DIRAC version:", result['Value']['DIRAC'] ) if result['Value']['Extensions']: for e, v in result['Value']['Extensions'].items(): gLogger.notice( "%s version" % e, v ) gLogger.notice( '' ) elif option == "host": client = SystemAdministratorClient( self.host, self.port ) result = client.getHostInfo() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( '' ) gLogger.notice( "Host info:" ) gLogger.notice( '' ) fields = ['Parameter','Value'] records = [] for key, value in result['Value'].items(): records.append( [key, str( value ) ] ) printTable( fields, records ) elif option == "hosts": client = ComponentMonitoringClient() result = client.getHosts( {}, False, False ) if not result[ 'OK' ]: self.__errMsg( 'Error retrieving the list of hosts: %s' % ( result[ 'Message' ] ) ) else: hostList = result[ 'Value' ] gLogger.notice( '' ) gLogger.notice( ' ' + 'Host'.center( 32 ) + ' ' + 'CPU'.center( 34 ) + ' ' ) gLogger.notice( ( '-' * 69 ) ) for element in hostList: gLogger.notice( '|' + element[ 'HostName' ].center( 32 ) + '|' + element[ 'CPU' ].center( 34 ) + '|' ) gLogger.notice( ( '-' * 69 ) ) gLogger.notice( '' ) elif option == "errors": self.getErrors( argss ) elif option == "installations": self.getInstallations( argss ) elif option == "doc": if len( argss ) > 2: if argss[0] in [ 'service', 'agent' ]: compType = argss[0] compSystem = argss[1] compModule = argss[2] client = SystemAdministratorClient( self.host, self.port ) result = client.getComponentDocumentation( compType, compSystem, compModule ) if result[ 'OK' ]: gLogger.notice( result[ 'Value' ] ) else: self.__errMsg( result[ 'Message' ] ) else: gLogger.notice( self.do_show.__doc__ ) else: gLogger.notice( self.do_show.__doc__ ) else: gLogger.notice( "Unknown option:", option )
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_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 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 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']: print " ERROR:", result['Message'] else: print pprint.pprint( result['Value'] ) elif option == 'installed': client = SystemAdministratorClient( self.host, self.port ) result = client.getInstalledComponents() if not result['OK']: print " ERROR:", result['Message'] else: print pprint.pprint( result['Value'] ) elif option == 'setup': client = SystemAdministratorClient( self.host, self.port ) result = client.getSetupComponents() if not result['OK']: print " ERROR:", result['Message'] else: print pprint.pprint( result['Value'] ) elif option == 'status': client = SystemAdministratorClient( self.host, self.port ) result = client.getOverallStatus() if not result['OK']: print "ERROR:", result['Message'] else: rDict = result['Value'] print print " System", ' '*20, 'Name', ' '*15, 'Type', ' '*13, 'Setup Installed Runit Uptime PID' print '-' * 116 for compType in rDict: for system in rDict[compType]: for component in rDict[compType][system]: if rDict[compType][system][component]['Installed']: print system.ljust( 28 ), component.ljust( 28 ), compType.lower()[:-1].ljust( 7 ), if rDict[compType][system][component]['Setup']: print 'SetUp'.rjust( 12 ), else: print 'NotSetup'.rjust( 12 ), if rDict[compType][system][component]['Installed']: print 'Installed'.rjust( 12 ), else: print 'NotInstalled'.rjust( 12 ), print str( rDict[compType][system][component]['RunitStatus'] ).ljust( 7 ), print str( rDict[compType][system][component]['Timeup'] ).rjust( 7 ), print str( rDict[compType][system][component]['PID'] ).rjust( 8 ), print 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']: print "ERROR:", result['Message'] return resultSW = client.getAvailableDatabases() if not resultSW['OK']: print "ERROR:", 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']: print "ERROR:", 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']: print "ERROR:", 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 == "errors": self.getErrors( argss ) else: print "Unknown option:", option
""" __RCSID__ = "$Id$" # from DIRAC.Core.Utilities import InstallTools # from DIRAC import gConfig InstallTools.exitOnError = True # from DIRAC.Core.Base import Script Script.setUsageMessage( '\n'.join( [ __doc__.split( '\n' )[1], 'Usage:', ' %s [option|cfgFile] ... DB ...' % Script.scriptName, 'Arguments:', ' DB: Name of the Database (mandatory)'] ) ) Script.parseCommandLine() args = Script.getPositionalArgs() # if len( args ) < 1: Script.showHelp() exit( -1 ) InstallTools.getMySQLPasswords() for db in args: result = InstallTools.installDatabase( db ) if not result['OK']: print "ERROR: failed to correctly install %s" % db,result['Message'] else: extension, system = result['Value'] InstallTools.addDatabaseOptionsToCS( gConfig, system, db, True )
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 hosts - show all available hosts show installations [ list | current | -n <Name> | -h <Host> | -s <System> | -m <Module> | -t <Type> | -itb <InstallationTime before> | -ita <InstallationTime after> | -utb <UnInstallationTime before> | -uta <UnInstallationTime after> ]* - show all the installations of components that match the given 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: gLogger.notice( 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: gLogger.notice( '' ) 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: gLogger.notice( '' ) 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: gLogger.notice( '' ) pprint.pprint( result['Value'] ) elif option == 'project': result = SystemAdministratorClient( self.host, self.port ).getProject() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( "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'] gLogger.notice( '' ) for db in sw: if db in installed: gLogger.notice( db.rjust( 25 ), ': Installed' ) else: gLogger.notice( db.rjust( 25 ), ': Not installed' ) if not sw: gLogger.notice( "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']: gLogger.notice( '' ) for par, value in result['Value'].items(): gLogger.notice( ( par.rjust( 28 ), ':', value ) ) else: gLogger.notice( "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: gLogger.notice( '' ) gLogger.notice( "Setup:", result['Value']['Setup'] ) gLogger.notice( "DIRAC version:", result['Value']['DIRAC'] ) if result['Value']['Extensions']: for e, v in result['Value']['Extensions'].items(): gLogger.notice( "%s version" % e, v ) gLogger.notice( '' ) elif option == "host": client = SystemAdministratorClient( self.host, self.port ) result = client.getHostInfo() if not result['OK']: self.__errMsg( result['Message'] ) else: gLogger.notice( '' ) gLogger.notice( "Host info:" ) gLogger.notice( '' ) fields = ['Parameter','Value'] records = [] for key, value in result['Value'].items(): records.append( [key, str( value ) ] ) printTable( fields, records ) elif option == "hosts": client = ComponentMonitoringClient() result = client.getHosts( {}, False, False ) if not result[ 'OK' ]: self.__errMsg( 'Error retrieving the list of hosts: %s' % ( result[ 'Message' ] ) ) else: hostList = result[ 'Value' ] gLogger.notice( '' ) gLogger.notice( ' ' + 'Host'.center( 32 ) + ' ' + 'CPU'.center( 34 ) + ' ' ) gLogger.notice( ( '-' * 69 ) ) for element in hostList: gLogger.notice( '|' + element[ 'HostName' ].center( 32 ) + '|' + element[ 'CPU' ].center( 34 ) + '|' ) gLogger.notice( ( '-' * 69 ) ) gLogger.notice( '' ) elif option == "errors": self.getErrors( argss ) elif option == "installations": self.getInstallations( argss ) else: gLogger.notice( "Unknown option:", option )
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 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 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']: print " ERROR:", result['Message'] else: print pprint.pprint(result['Value']) elif option == 'installed': client = SystemAdministratorClient(self.host, self.port) result = client.getInstalledComponents() if not result['OK']: print " ERROR:", result['Message'] else: print pprint.pprint(result['Value']) elif option == 'setup': client = SystemAdministratorClient(self.host, self.port) result = client.getSetupComponents() if not result['OK']: print " ERROR:", result['Message'] else: print pprint.pprint(result['Value']) elif option == 'status': client = SystemAdministratorClient(self.host, self.port) result = client.getOverallStatus() if not result['OK']: print "ERROR:", result['Message'] else: rDict = result['Value'] print print " System", ' ' * 20, 'Name', ' ' * 15, 'Type', ' ' * 13, 'Setup Installed Runit Uptime PID' print '-' * 116 for compType in rDict: for system in rDict[compType]: for component in rDict[compType][system]: if rDict[compType][system][component]['Installed']: print system.ljust(28), component.ljust( 28), compType.lower()[:-1].ljust(7), if rDict[compType][system][component]['Setup']: print 'SetUp'.rjust(12), else: print 'NotSetup'.rjust(12), if rDict[compType][system][component][ 'Installed']: print 'Installed'.rjust(12), else: print 'NotInstalled'.rjust(12), print str(rDict[compType][system][component] ['RunitStatus']).ljust(7), print str(rDict[compType][system][component] ['Timeup']).rjust(7), print str(rDict[compType][system][component] ['PID']).rjust(8), print 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']: print "ERROR:", result['Message'] return resultSW = client.getAvailableDatabases() if not resultSW['OK']: print "ERROR:", 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']: print "ERROR:", 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']: print "ERROR:", 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 == "errors": self.getErrors(argss) else: print "Unknown option:", option