Example #1
0
def check_process_status(pid_file):
    """
  Function checks whether process is running.
  Process is considered running, if pid file exists, and process with
  a pid, mentioned in pid file is running
  If process is not running, will throw ComponentIsNotRunning exception

  @param pid_file: path to service pid file
  """
    from resource_management.core import sudo

    if not pid_file or not os.path.isfile(pid_file):
        Logger.info("Pid file {0} is empty or does not exist".format(
            str(pid_file)))
        raise ComponentIsNotRunning()

    try:
        pid = int(sudo.read_file(pid_file))
    except:
        Logger.info(
            "Pid file {0} does not exist or does not contain a process id number"
            .format(pid_file))
        raise ComponentIsNotRunning()

    try:
        # Kill will not actually kill the process
        # From the doc:
        # If sig is 0, then no signal is sent, but error checking is still
        # performed; this can be used to check for the existence of a
        # process ID or process group ID.
        sudo.kill(pid, 0)
    except OSError:
        Logger.info("Process with pid {0} is not running. Stale pid file"
                    " at {1}".format(pid, pid_file))
        raise ComponentIsNotRunning()
Example #2
0
    def status(self, env):
        print('status')
        from resource_management.core import sudo
        import params
        env.set_params(params)
        # file_handle=open('/root/1.txt',mode='a')
        # file_handle.write('\n' + "check_pricess_status : " + str(check_process_status(status_params.pid_file)))
        # file_handle.close()
        # # Use built-in method to check status using pidfile
        # check_process_status(status_params.pid_file)
        if (os.path.exists('/data/redis/redis/cluster') == False):
            raise Exception('---> /data/redis/redis/cluster目录不存在!!! <---')

        ## 判断每个redis实例的pid文件是否存在,不存在则抛异常
        redis_node_detail = params.redis_node_detail
        CLUSTER_HOME = '/data/redis/redis'
        REDIS_HOME = '/opt/redis/redis-4.0.8'
        localIP = socket.gethostbyname(socket.gethostname())
        for i in range(len(redis_node_detail.split(','))):
            if (redis_node_detail.split(',')[i].split(':')[0] == localIP):
                port_num = int(redis_node_detail.split(',')[i].split(':')[1])
                for j in range(port_num):
                    port = 7000 + j
                    if (os.path.exists("/data/redis/redis/cluster/" +
                                       str(port) + "/redis.pid") == False):
                        raise ComponentIsNotRunning()

                    pid = int(
                        sudo.read_file("/data/redis/redis/cluster/" +
                                       str(port) + "/redis.pid"))
                    try:
                        sudo.kill(pid, 0)
                    except:
                        raise ComponentIsNotRunning()
Example #3
0
def check_process_status(pid_file):
  """
  Function checks whether process is running.
  Process is considered running, if pid file exists, and process with
  a pid, mentioned in pid file is running
  If process is not running, will throw ComponentIsNotRunning exception

  @param pid_file: path to service pid file
  """
  if not pid_file or not os.path.isfile(pid_file):
    raise ComponentIsNotRunning()
  
  try:
    pid = int(sudo.read_file(pid_file))
  except:
    Logger.debug("Pid file {0} does not exist".format(pid_file))
    raise ComponentIsNotRunning()

  code, out = shell.call(["ps","-p", str(pid)])
  
  if code:
    Logger.debug("Process with pid {0} is not running. Stale pid file"
              " at {1}".format(pid, pid_file))
    raise ComponentIsNotRunning()
  pass
def check_process_status(pid_file):
  """
  Function checks whether process is running.
  Process is considered running, if pid file exists, and process with
  a pid, mentioned in pid file is running
  If process is not running, will throw ComponentIsNotRunning exception

  @param pid_file: path to service pid file
  """
  if not pid_file or not os.path.isfile(pid_file):
    raise ComponentIsNotRunning()
  with open(pid_file, "r") as f:
    try:
      pid = int(f.read())
    except:
      Logger.debug("Pid file {0} does not exist".format(pid_file))
      raise ComponentIsNotRunning()
    try:
      # Kill will not actually kill the process
      # From the doc:
      # If sig is 0, then no signal is sent, but error checking is still
      # performed; this can be used to check for the existence of a
      # process ID or process group ID.
      os.kill(pid, 0)
    except OSError:
      Logger.debug("Process with pid {0} is not running. Stale pid file"
                " at {1}".format(pid, pid_file))
      raise ComponentIsNotRunning()
  pass
 def sdc_status(self, pid):
     from resource_management.core.exceptions import ComponentIsNotRunning
     print "checking status..."
     try:
         if not pid:
             raise ComponentIsNotRunning()
     except Exception, e:
         raise ComponentIsNotRunning()
Example #6
0
 def status(self, env):
     # Read from the status file, and check the index exists
     if not os.path.exists(self.status_file):
         raise ComponentIsNotRunning()
     klfile = None
     with open(self.status_file) as fp:
         klfile = fp.read().split()[0].strip()
     if len(klfile) < 5 or (not os.path.exists(klfile)):
         raise ComponentIsNotRunning()
     super(KaveLanding, self).status(env)
Example #7
0
 def status(self, env):
     print "status"
     import params
     env.set_params(params)
     print str(datetime.now()) + ":check docker container status"
     #cmd = format("docker inspect {containerName} | grep running")
     try:
         container = Elasticsearch.cli.inspect_container('drs-search')
         isRunning = container['State']['Running']
         print isRunning
         if isRunning == False:
             raise ComponentIsNotRunning()
     except Exception, e:
         traceback.print_exc()
         raise ComponentIsNotRunning()
Example #8
0
 def status(self, env):
     import subprocess
     check = subprocess.Popen('systemctl is-active --quiet lcm-ui', shell=True)
     check.wait()
     if int(check.returncode) != 0:
         raise ComponentIsNotRunning()
     return True
Example #9
0
def supervisord_check_status(component_name):
    try:
        Execute(
            format(
                "supervisorctl status kafka-{component_name} | grep RUNNING"))
    except Fail:
        raise ComponentIsNotRunning()
Example #10
0
def service_check(cmd, user, label):
    """
    Executes a service check command that adheres to LSB-compliant
    return codes.  The return codes are interpreted as defined
    by the LSB.

    See http://refspecs.linuxbase.org/LSB_3.0.0/LSB-PDA/LSB-PDA/iniscrptact.html
    for more information.

    :param cmd: The service check command to execute.
    :param label: The name of the service.
    """
    Logger.info(
        "Performing service check; cmd={0}, user={1}, label={2}".format(
            cmd, user, label))
    rc, out, err = get_user_call_output(cmd, user, is_checked_call=False)

    if len(err) > 0:
        Logger.error(err)

    if rc in [1, 2, 3]:
        # if return code in [1, 2, 3], then 'program is not running' or 'program is dead'
        Logger.info("{0} is not running".format(label))
        raise ComponentIsNotRunning()

    elif rc == 0:
        # if return code = 0, then 'program is running or service is OK'
        Logger.info("{0} is running".format(label))

    else:
        # else service state is unknown
        err_msg = "{0} service check failed; cmd '{1}' returned {2}".format(
            label, cmd, rc)
        Logger.error(err_msg)
        raise ExecutionFailed(err_msg, rc, out, err)
def security_auth(configs, host_name, solr_user):
    """
  Call kinit before pursuit with any other action
  :type configs dict
  :type host_name str
  :type solr_user str
  """
    solr_kerberos_keytab = configs[
        SMOKEUSER_KEYTAB_KEY] if SMOKEUSER_KEYTAB_KEY in configs else None
    solr_principal = configs[SMOKEUSER_PRINCIPAL_KEY].replace(
        '_HOST',
        host_name.lower()) if SMOKEUSER_PRINCIPAL_KEY in configs else None
    krb_executable_search_paths = configs[
        KRB_EXEC_SEARCH_PATHS_KEY] if KRB_EXEC_SEARCH_PATHS_KEY in configs else None
    kinit_path_local = get_kinit_path(krb_executable_search_paths)

    if not solr_principal or not solr_kerberos_keytab:
        raise ComponentIsNotRunning(
            "Error: solr principal or solr kerberos keytab can't be None")

    kinit_cmd = "{kinit_path_local} -kt {solr_kerberos_keytab} {solr_principal};".format(
        kinit_path_local=kinit_path_local,
        solr_kerberos_keytab=solr_kerberos_keytab,
        solr_principal=solr_principal)

    Execute(kinit_cmd, user=solr_user)
Example #12
0
    def status(self, env):
        import params
        env.set_params(params)
        processes = get_flume_status(params.flume_conf_dir, params.flume_run_dir)
        expected_agents = find_expected_agent_names(params.flume_conf_dir)

        json = {}
        json['processes'] = processes
        self.put_structured_out(json)

        if len(expected_agents) > 0:
            for proc in processes:
                if not proc.has_key('status') or proc['status'] == 'NOT_RUNNING':
                    raise ComponentIsNotRunning()
        elif len(expected_agents) == 0 and 'INSTALLED' == get_desired_state():
            raise ComponentIsNotRunning()
Example #13
0
    def status(self, env):
        import status_params
        env.set_params(status_params)
        commands = Commands(status_params)

        if not commands.is_topology_active():
            raise ComponentIsNotRunning()
Example #14
0
def mysql_service(action='start'):
    daemon_name = get_daemon_name()

    status_cmd = format("pgrep -l '^{process_name}$'")
    cmd = ('service', daemon_name, action)

    if action == 'status':
        try:
            Execute(status_cmd)
        except Fail:
            raise ComponentIsNotRunning()
    elif action == 'stop':
        import params
        Execute(
            cmd,
            logoutput=True,
            only_if=status_cmd,
            sudo=True,
        )
    elif action == 'start':
        import params
        Execute(
            cmd,
            logoutput=True,
            not_if=status_cmd,
            sudo=True,
        )
Example #15
0
 def status(self, env):
     cmd = 'ps -ef | grep proc_rangerkms | grep -v grep'
     code, output = shell.call(cmd, timeout=20)
     if code != 0:
         Logger.debug('KMS process not running')
         raise ComponentIsNotRunning()
     pass
Example #16
0
 def status(self, env):
     import os.path
     import params
     if not os.path.isfile(
             os.path.join(params.qw_master_pid_dir, "qw_master.pid")):
         raise ComponentIsNotRunning()
     print "QW Master Status..."
Example #17
0
 def check_flink_status(self, pid_file):
     from resource_management.core.exceptions import ComponentIsNotRunning
     from resource_management.core import sudo
     from subprocess import PIPE, Popen
     import shlex
     if not os.path.exists(pid_file) or not os.path.isfile(pid_file):
         raise ComponentIsNotRunning()
     try:
         pid = str(sudo.read_file(pid_file))
         cmd_line = "/usr/bin/yarn application -list"
         args = shlex.split(cmd_line)
         proc = Popen(args, stdout=PIPE)
         p = str(proc.communicate()[0].split())
         if p.find(pid.strip()) < 0:
             raise ComponentIsNotRunning()
     except Exception, e:
         raise ComponentIsNotRunning()
Example #18
0
def assert_component_running(component_name):
  """
  Based on the port and process identifies the status of the component
  """
  port_number = common.get_local_hawq_site_property_value(hawq_constants.COMPONENT_ATTRIBUTES_MAP[component_name]['port_property'])
  return_code, _ = call(utils.generate_hawq_process_status_cmd(component_name, port_number))
  if return_code:
    raise ComponentIsNotRunning()
Example #19
0
 def status(self, env):
     from params import status_params
     env.set_params(status_params)
     cmd = format('curl --max-time 3 {hostname}:{metron_rest_port}')
     try:
         get_user_call_output(cmd, user=status_params.metron_user)
     except ExecutionFailed:
         raise ComponentIsNotRunning()
Example #20
0
 def deal(self, action):
     import storage_params
     daemon_name = storage_params.server_name
     cmd = ('service', daemon_name, action)
     if action == 'status':
         try:
             Execute(cmd)
         except Fail, e:
             raise ComponentIsNotRunning()
Example #21
0
 def status(self, env):
     from params import daemon_control_script
     try:
         Execute('{0} status'.format(daemon_control_script))
     except ExecutionFailed as ef:
         if ef.code == 3:
             raise ComponentIsNotRunning("ComponentIsNotRunning")
         else:
             raise ef
Example #22
0
 def status(self, env):
     launcher = '/usr/hdp/current/presto-worker/bin/launcher'
     try:
         Execute('{0} status'.format(launcher))
     except ExecutionFailed as ef:
         if ef.code == 3:
             raise ComponentIsNotRunning("ComponentIsNotRunning")
         else:
             raise ef
 def status(self, env):
     try:
         Execute(
             'export AZ_CNT=`ps -ef |grep -v grep |grep azkaban-exec-server | wc -l` && `if [ $AZ_CNT -ne 0 ];then exit 0;else exit 3;fi `'
         )
     except ExecutionFailed as ef:
         if ef.code == 3:
             raise ComponentIsNotRunning("ComponentIsNotRunning")
         else:
             raise ef
Example #24
0
  def status(self, env):
    import params
    env.set_params(params)
    processes = get_flume_status(params.flume_conf_dir, params.flume_run_dir)
    expected_agents = find_expected_agent_names(params.flume_conf_dir)

    json = {}
    json['processes'] = processes
    self.put_structured_out(json)

    # only throw an exception if there are agents defined and there is a
    # problem with the processes; if there are no agents defined, then
    # the service should report STARTED (green) ONLY if the desired state is started.  otherwise, INSTALLED (red)
    if len(expected_agents) > 0:
      for proc in processes:
        if not proc.has_key('status') or proc['status'] == 'NOT_RUNNING':
          raise ComponentIsNotRunning()
    elif len(expected_agents) == 0 and 'INSTALLED' == get_desired_state():
      raise ComponentIsNotRunning()
 def service_check(self, env):
     import params
     env.set_params(params)
     status_cmd = format("pgrep nifi")
     code, output = shell.call(status_cmd, timeout=10)
     if code == 0:
         Logger.info('Nifi is up and running')
     else:
         Logger.debug('Nifi is not running')
         raise ComponentIsNotRunning()
Example #26
0
 def status(self, env):
     # need to save pid in filr and retrieve to see the value of status
     import subprocess
     # use the bind address/port number!
     p = subprocess.Popen([self.symlink + self.statcmd],
                          stdout=subprocess.PIPE)
     stdout, stderr = p.communicate()
     if '"running"' not in stdout:
         print stdout, stderr
         raise ComponentIsNotRunning()
Example #27
0
    def status(self, env):
        import params

        #call status
        cmd = params.base_dir + '/bin/tachyon status slave'

        try:
            Execute(cmd)
        except Fail:
            raise ComponentIsNotRunning()
Example #28
0
    def service_check(self, env):
        import params

        env.set_params(params)
        cmd = 'ps -ef | grep proc_rangerkms | grep -v grep'
        code, output = shell.call(cmd, timeout=20)
        if code == 0:
            Logger.info('KMS process up and running')
        else:
            Logger.debug('KMS process not running')
            raise ComponentIsNotRunning()
Example #29
0
  def status(self, env):
    cmd = 'ps -ef | grep proc_rangeradmin | grep -v grep'
    code, output = shell.call(cmd, timeout=20)

    if code != 0:
      if self.is_ru_rangeradmin_in_progress():
         Logger.info('Ranger admin process not running - skipping as rolling upgrade is in progress')
      else:
         Logger.debug('Ranger admin process not running')
         raise ComponentIsNotRunning()
    pass
Example #30
0
    def status(self, env):
        import params
        import os
        import subprocess

        check = subprocess.Popen('systemctl status airflow-webserver',
                                 shell=True)
        check.wait()
        if int(check.returncode) != 0:
            raise ComponentIsNotRunning()
        return True