def kill_stop_server(server, pid): if pid is None: log_error( "Cannot forcibly stop the server because the server's process" " ID cannot be determined; pid file '%s' does not exist." % server.get_pid_file_path()) return False log_info("Forcibly stopping server '%s'...\n" % server.id) log_info("Sending kill -1 (HUP) signal to server '%s' (pid=%s)..." % (server.id, pid)) kill_process(pid, force=False) log_info("Will now wait for server '%s' (pid=%s) to die." % (server.id, pid)) wait_for(pid_dead_predicate(pid), timeout=MAX_SHUTDOWN_WAIT) if is_pid_alive(pid): log_error("Failed to kill server process with -1 (HUP).") log_info("Sending kill -9 (SIGKILL) signal to server" "'%s' (pid=%s)..." % (server.id, pid)) kill_process(pid, force=True) log_info("Will now wait for server '%s' (pid=%s) to die." % (server.id, pid)) wait_for(pid_dead_predicate(pid), timeout=MAX_SHUTDOWN_WAIT) if not is_pid_alive(pid): log_info("Forcefully-stopped server '%s'." % server.id) return True else: log_error("Forceful stop of server '%s' failed." % server.id) return False
def kill_stop_server(server, pid): if pid is None: log_error("Cannot forcibly stop the server because the server's process" " ID cannot be determined; pid file '%s' does not exist." % server.get_pid_file_path()) return False log_info("Forcibly stopping server '%s'...\n" % server.id) log_info("Sending kill -1 (HUP) signal to server '%s' (pid=%s)..." % (server.id, pid)) kill_process(pid, force=False) log_info("Will now wait for server '%s' (pid=%s) to die." % (server.id, pid)) wait_for(pid_dead_predicate(pid), timeout=MAX_SHUTDOWN_WAIT) if is_pid_alive(pid): log_error("Failed to kill server process with -1 (HUP).") log_info("Sending kill -9 (SIGKILL) signal to server" "'%s' (pid=%s)..." % (server.id, pid)) kill_process(pid, force=True) log_info("Will now wait for server '%s' (pid=%s) to die." % (server.id, pid)) wait_for(pid_dead_predicate(pid), timeout=MAX_SHUTDOWN_WAIT) if not is_pid_alive(pid): log_info("Forcefully-stopped server '%s'." % server.id) return True else: log_error("Forceful stop of server '%s' failed." % server.id) return False
def server_started(): # check if the command failed if not is_pid_alive(mongod_pid): raise MongoctlException("Could not start the server. Please check" " the log file.") return server.is_online()
def quiet_kill_test_server(self, server_id): server_ps_output = commands.getoutput("ps -o pid -o command -ae | " "grep %s" % server_id) pid_lines = server_ps_output.split("\n") for line in pid_lines: if line == "": continue pid = line.strip().split(" ")[0] if pid == "": continue pid = int(pid) if is_pid_alive(pid): print ("PID for server %s is still alive. Killing..." % server_id) kill_process(pid, force=True)
def quiet_kill_test_server(self, server_id): server_ps_output = commands.getoutput("ps -o pid -o command -ae | " "grep %s" % server_id) pid_lines = server_ps_output.split("\n") for line in pid_lines: if line == '': continue pid = line.strip().split(" ")[0] if pid == '': continue pid = int(pid) if is_pid_alive(pid): print ("PID for server %s is still alive. Killing..." % server_id) kill_process(pid, force=True)
def is_server_pid_alive(self): pid = self.get_pid() return pid and is_pid_alive(pid)
def server_stopped(): return (not server.is_online() and (pid is None or not is_pid_alive(pid)))
def pid_dead(): return not is_pid_alive(pid)