def restartHost(hostName): """ Restart all systems and components of a host :param str hostName: name of the host you want to restart """ host, port = parseHostname(hostName) gLogger.notice("Pinging %s ..." % host) client = SystemAdministratorClient(host, port) result = client.ping() if not result['OK']: gLogger.error("Could not connect to %s: %s" % (host, result['Message'])) return result gLogger.notice("Host %s is active" % host) gLogger.notice("Initiating restart of all systems and components") # This restart call will always return S_ERROR because of SystemAdministrator restart # Connection will be lost to the host result = client.restartComponent('*', '*') if result['Message'] == "Peer closed connection": gLogger.notice( "Restarted all systems on %s : connection to SystemAdministrator lost" % host) return S_OK(result['Message']) gLogger.error("Received unxpected message: %s" % result['Message']) return result
def __actionHost( self ): """ Restart all DIRAC components on a given host """ if not "hostname" in request.params: return { "success" : "false" , "error" : "No hostname given" } hosts = request.params[ "hostname" ].split( "," ) DN = getUserDN() group = getSelectedGroup() self.actionSuccess = list() self.actionFailed = list() for i in hosts: client = SystemAdministratorClient( str( i ) , None , delegatedDN=DN , delegatedGroup=group ) if self.action is "restart": result = client.restartComponent( str( "*" ) , str( "*" ) ) elif self.action is "revert": result = client.revertSoftware() else: error = i + ": Action %s is not defined" % self.action self.actionFailed.append( error ) continue gLogger.always( result ) if not result[ "OK" ]: if result[ "Message" ].find( "Unexpected EOF" ) > 0: msg = "Signal 'Unexpected EOF' received. Most likely DIRAC components" msg = i + ": " + msg + " were successfully restarted." self.actionSuccess.append( msg ) continue error = i + ": " + result[ "Message" ] self.actionFailed.append( error ) gLogger.error( error ) else: gLogger.info( result[ "Value" ] ) self.actionSuccess.append( i ) self.prefix = "Host" return self.__aftermath()
def do_restart( self, args ): """ Restart services or agents or database server usage: restart <system|*> <service|agent|*> restart mysql """ if not args: gLogger.notice( self.do_restart.__doc__ ) return argss = args.split() option = argss[0] del argss[0] if option != 'mysql': if option != "*": if len( argss ) < 1: gLogger.notice( self.do_restart.__doc__ ) return system = option if system != '*': component = argss[0] else: component = '*' client = SystemAdministratorClient( self.host, self.port ) result = client.restartComponent( system, component ) if not result['OK']: if system == '*': gLogger.notice( "All systems are restarted, connection to SystemAdministrator is lost" ) else: self.__errMsg( result['Message'] ) else: if system != '*' and component != '*': gLogger.notice( "\n%s_%s started successfully, runit status:\n" % ( system, component ) ) else: gLogger.notice( "\nComponents started successfully, runit status:\n" ) for comp in result['Value']: gLogger.notice( ( comp.rjust( 32 ), ':', result['Value'][comp]['RunitStatus'] ) ) else: gLogger.notice( "Not yet implemented" )
def do_restart( self, args ): """ Restart services or agents or database server usage: restart <system|*> <service|agent|*> restart mysql """ if not args: gLogger.notice( self.do_restart.__doc__ ) return argss = args.split() option = argss[0] del argss[0] if option != 'mysql': if option != "*": if len( argss ) < 1: gLogger.notice( self.do_restart.__doc__ ) return system = option if system != '*': component = argss[0] else: component = '*' client = SystemAdministratorClient( self.host, self.port ) result = client.restartComponent( system, component ) if not result['OK']: if system == '*': gLogger.notice( "All systems are restarted, connection to SystemAdministrator is lost" ) else: self.__errMsg( result['Message'] ) else: if system != '*' and component != '*': gLogger.notice( "\n%s_%s started successfully, runit status:\n" % ( system, component ) ) else: gLogger.notice( "\nComponents started successfully, runit status:\n" ) for comp in result['Value']: gLogger.notice( ( comp.rjust( 32 ), ':', result['Value'][comp]['RunitStatus'] ) ) else: gLogger.notice( "Not yet implemented" )
def __componentAction( self , action = None ): """ Actions which should be done on components. The only parameters is an action to perform. Returns standard JSON response structure with with service response or error messages """ DN = getUserDN() group = getSelectedGroup() if ( not action ) or ( not len( action ) > 0 ): error = "Action is not defined or has zero length" gLogger.debug( error ) return { "success" : "false" , "error" : error } if action not in [ "restart" , "start" , "stop" , "uninstall" ]: error = "The request parameters action '%s' is unknown" % action gLogger.debug( error ) return { "success" : "false" , "error" : error } self.action = action result = dict() for i in request.params: if i == "action": continue target = i.split( " @ " , 1 ) if not len( target ) == 2: continue system = request.params[ i ] gLogger.always( "System: %s" % system ) host = target[ 1 ] gLogger.always( "Host: %s" % host ) component = target[ 0 ] gLogger.always( "Component: %s" % component ) if not host in result: result[ host ] = list() result[ host ].append( [ system , component ] ) if not len( result ) > 0: error = "Failed to get component(s) for %s" % action gLogger.debug( error ) return { "success" : "false" , "error" : error } gLogger.always( result ) self.actionSuccess = list() self.actionFailed = list() for hostname in result.keys(): if not len( result[ hostname ] ) > 0: continue client = SystemAdministratorClient( hostname , None , delegatedDN=DN , delegatedGroup=group ) for i in result[ hostname ]: system = i[ 0 ] component = i[ 1 ] try: if action == "restart": result = client.restartComponent( system , component ) elif action == "start": result = client.startComponent( system , component ) elif action == "stop": result = client.stopComponent( system , component ) elif action == "uninstall": result = client.uninstallComponent( system , component ) else: result = list() result[ "Message" ] = "Action %s is not valid" % action except Exception, x: result = list() result[ "Message" ] = "Exception: %s" % str( x ) gLogger.debug( "Result: %s" % result ) if not result[ "OK" ]: error = hostname + ": " + result[ "Message" ] self.actionFailed.append( error ) gLogger.error( "Failure during component %s: %s" % ( action , error ) ) else: gLogger.always( "Successfully %s component %s" % ( action , component ) ) self.actionSuccess.append( component )