#!/usr/bin/env python”””Licensed to the Apache Software Foundation (ASF) under oneor more contributor license agreements. See the NOTICE filedistributed with this work for additional informationregarding copyright ownership. The ASF licenses this fileto you under the Apache License, Version 2.0 (the”License”); you may not use this file except in compliancewith the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an “AS IS” BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.”””import sys
# def check_process_status(pid_file): # if not pid_file or not os.path.isfile(pid_file): # logging.error(“Pid file {0} is empty or does not exist”.format(str(pid_file))) # return False # else: # pid = -1 # try: # pid = int(read_file(pid_file)) # except RuntimeError: # logging.error(“Pid file {0} does not exist or does not contain a process id number”.format(pid_file)) # 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) # logging.info(“process already exists! “) # process_is_exist = True # except OSError: # logging.error(“Process with pid {0} is not running. Stale pid file” # ” at {1}”.format(pid, pid_file)) # process_is_exist = False # return process_is_exist # def status(self, env): # # Import properties defined in -env.xml file from the status_params class # import status_params # # This allows us to access the params.prometheus_pid_file property as # # format(‘{prometheus_pid_file}’) # env.set_params(status_params) # # try: # # pid_file = glob.glob(status_params.prometheus_pid_file)[0] # # except IndexError: # # pid_file = ” # # Use built-in method to check status using pidfile # check_process_status(status_params.prometheus_pid_file) def check_prometheus_status(self, pid_file):
from datetime import datetime
from resource_management.core.exceptions import ComponentIsNotRunning