1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

Merge pull request #760 from AlanCoding/parse_fix_ubuntu

Fix scan_services parsing error with Ubuntu14.04
This commit is contained in:
Alan Rominger 2016-02-03 08:35:16 -05:00
commit 1e7d734b50

View File

@ -72,22 +72,18 @@ class ServiceScanService(BaseService):
else: else:
service_state = "stopped" service_state = "stopped"
services.append({"name": service_name, "state": service_state, "source": "sysv"}) services.append({"name": service_name, "state": service_state, "source": "sysv"})
p = re.compile('^\s?(?P<name>.*)\s(?P<goal>\w+)\/(?P<state>\w+)(\,\sprocess\s(?P<pid>[0-9]+))?\s*$')
rc, stdout, stderr = self.module.run_command("%s list" % initctl_path) rc, stdout, stderr = self.module.run_command("%s list" % initctl_path)
real_stdout = stdout.replace("\r","") real_stdout = stdout.replace("\r","")
for line in real_stdout.split("\n"): for line in real_stdout.split("\n"):
line_data = line.split() m = p.match(line)
if len(line_data) < 2: if not m:
continue continue
service_name = line_data[0] service_name = m.group('name')
if line_data[1].find("/") == -1: # we expect this to look like: start/running service_goal = m.group('goal')
continue service_state = m.group('state')
service_goal = line_data[1].split("/")[0] if m.group('pid'):
service_state = line_data[1].split("/")[1].replace(",","") pid = m.group('pid')
if len(line_data) > 3: # If there's a pid associated with the service it'll be on the end of this string "process 418"
if line_data[2] == 'process':
pid = line_data[3]
else:
pid = None
else: else:
pid = None # NOQA pid = None # NOQA
payload = {"name": service_name, "state": service_state, "goal": service_goal, "source": "upstart"} payload = {"name": service_name, "state": service_state, "goal": service_goal, "source": "upstart"}