Commit d070a9f8 authored by Rafael Monnerat's avatar Rafael Monnerat

apache_mpm_watchdog: Fixes for argparse usage and timeout.

parent 5f92ce8a
...@@ -5,6 +5,7 @@ import os ...@@ -5,6 +5,7 @@ import os
import psutil import psutil
import json import json
import time import time
import argparse
search_pid_regex = r"</td><td.*?>(.+?)</td><td>yes \(old gen\)</td>" search_pid_regex = r"</td><td.*?>(.+?)</td><td>yes \(old gen\)</td>"
...@@ -43,7 +44,7 @@ def getServerStatus(url, user, password): ...@@ -43,7 +44,7 @@ def getServerStatus(url, user, password):
except requests.exceptions.ConnectionError: except requests.exceptions.ConnectionError:
return return
def watchServerStatus(pid_dict, server_status): def watchServerStatus(pid_dict, server_status, timeout):
_pid_dict = pid_dict.copy() _pid_dict = pid_dict.copy()
for i in re.findall(search_pid_regex, server_status): for i in re.findall(search_pid_regex, server_status):
try: try:
...@@ -53,8 +54,8 @@ def watchServerStatus(pid_dict, server_status): ...@@ -53,8 +54,8 @@ def watchServerStatus(pid_dict, server_status):
# Ensure the process is actually an apache # Ensure the process is actually an apache
if process.cmdline()[0].endswith("/httpd"): if process.cmdline()[0].endswith("/httpd"):
pid_dict.setdefault(i, time.time() + timeout) _pid_dict.setdefault(i, time.time() + timeout)
if pid_dict[i] < time.time(): if _pid_dict[i] < time.time():
print "Sending signal -%s to %s" % (signal.SIGKILL, i) print "Sending signal -%s to %s" % (signal.SIGKILL, i)
os.kill(int(i), signal.SIGKILL) os.kill(int(i), signal.SIGKILL)
...@@ -63,7 +64,7 @@ def watchServerStatus(pid_dict, server_status): ...@@ -63,7 +64,7 @@ def watchServerStatus(pid_dict, server_status):
def main(): def main():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
# Address to ping to # Address to ping to
parser.add_argument("-u", "--url", required=True) parser.add_argument("--url", required=True)
# Force use ipv4 protocol # Force use ipv4 protocol
parser.add_argument("-u", "--user") parser.add_argument("-u", "--user")
parser.add_argument("-p", "--password") parser.add_argument("-p", "--password")
...@@ -79,7 +80,7 @@ def main(): ...@@ -79,7 +80,7 @@ def main():
if server_status is None: if server_status is None:
raise ValueError("Couldn't connect to server status page") raise ValueError("Couldn't connect to server status page")
pid_dict = watchServerStatus(pid_dict, server_status) pid_dict = watchServerStatus(pid_dict, server_status, args.timeout)
writeJSONFile(pid_dict, args.db) writeJSONFile(pid_dict, args.db)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment