parameters: (
          command,
          port,
          trans_factory=None,
          prot_factory=None)
return_statement: return 0
docstring: service_ctrl is a generic function to execute standard fb303 functions
  
      @param command: one of stop, start, reload, status, counters, name, alive
      @param port: service's port
      @param trans_factory: TTransportFactory to use for obtaining a TTransport. Default is
                            TBufferedTransportFactory
      @param prot_factory: TProtocolFactory to use for obtaining a TProtocol. Default is
                           TBinaryProtocolFactory
docstring_summary: service_ctrl is a generic function to execute standard fb303 functions
docstring_tokens: service_ctrl is a generic function to execute standard fb303 functions
function: def service_ctrl(
          command,
          port,
          trans_factory=None,
          prot_factory=None):
      """
      service_ctrl is a generic function to execute standard fb303 functions
  
      @param command: one of stop, start, reload, status, counters, name, alive
      @param port: service's port
      @param trans_factory: TTransportFactory to use for obtaining a TTransport. Default is
                            TBufferedTransportFactory
      @param prot_factory: TProtocolFactory to use for obtaining a TProtocol. Default is
                           TBinaryProtocolFactory
      """
  
      if command in ["status"]:
          try:
              status = fb303_wrapper('status', port, trans_factory, prot_factory)
              status_details = fb303_wrapper('get_status_details', port, trans_factory, prot_factory)
  
              msg = fb_status_string(status)
              if (len(status_details)):
                  msg += " - %s" % status_details
              print(msg)
              return 2 if status == fb_status.ALIVE else 3
          except:
              print("Failed to get status")
              return 3
  
      # scalar commands
      if command in ["version", "alive", "name"]:
          try:
              result = fb303_wrapper(command, port, trans_factory, prot_factory)
              print(result)
              return 0
          except:
              print("failed to get ", command)
              return 3
  
      # counters
      if command in ["counters"]:
          try:
              counters = fb303_wrapper('counters', port, trans_factory, prot_factory)
              for counter in counters:
                  print("%s: %d" % (counter.encode('utf-8'), counters[counter]))
              return 0
          except:
              print("failed to get counters")
              return 3
  
      # Only root should be able to run the following commands
      if os.getuid() == 0:
          # async commands
          if command in ["stop", "reload"]:
              try:
                  fb303_wrapper(command, port, trans_factory, prot_factory)
                  return 0
              except:
                  print("failed to tell the service to ", command)
                  return 3
      else:
          if command in ["stop", "reload"]:
              print("root privileges are required to stop or reload the service.")
              return 4
  
      print("The following commands are available:")
      for command in ["counters", "name", "version", "alive", "status"]:
          print("\t%s" % command)
      print("The following commands are available for users with root privileges:")
      for command in ["stop", "reload"]:
          print("\t%s" % command)
  
      return 0
function_tokens: def service_ctrl ( command , port , trans_factory = None , prot_factory = None ) : if command in [ "status" ] : try : status = fb303_wrapper ( 'status' , port , trans_factory , prot_factory ) status_details = fb303_wrapper ( 'get_status_details' , port , trans_factory , prot_factory ) msg = fb_status_string ( status ) if ( len ( status_details ) ) : msg += " - %s" % status_details print ( msg ) return 2 if status == fb_status . ALIVE else 3 except : print ( "Failed to get status" ) return 3 # scalar commands if command in [ "version" , "alive" , "name" ] : try : result = fb303_wrapper ( command , port , trans_factory , prot_factory ) print ( result ) return 0 except : print ( "failed to get " , command ) return 3 # counters if command in [ "counters" ] : try : counters = fb303_wrapper ( 'counters' , port , trans_factory , prot_factory ) for counter in counters : print ( "%s: %d" % ( counter . encode ( 'utf-8' ) , counters [ counter ] ) ) return 0 except : print ( "failed to get counters" ) return 3 # Only root should be able to run the following commands if os . getuid ( ) == 0 : # async commands if command in [ "stop" , "reload" ] : try : fb303_wrapper ( command , port , trans_factory , prot_factory ) return 0 except : print ( "failed to tell the service to " , command ) return 3 else : if command in [ "stop" , "reload" ] : print ( "root privileges are required to stop or reload the service." ) return 4 print ( "The following commands are available:" ) for command in [ "counters" , "name" , "version" , "alive" , "status" ] : print ( "\t%s" % command ) print ( "The following commands are available for users with root privileges:" ) for command in [ "stop" , "reload" ] : print ( "\t%s" % command ) return 0