mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 23:51:09 +03:00
Merge pull request #299 from chrismeyersfsu/fix-scan_services
for scan_services against RH machines. Do not depend on US language
This commit is contained in:
commit
8e8071b28f
@ -57,6 +57,7 @@ class ServiceScanService(BaseService):
|
|||||||
return None
|
return None
|
||||||
initctl_path = self.module.get_bin_path("initctl")
|
initctl_path = self.module.get_bin_path("initctl")
|
||||||
chkconfig_path = self.module.get_bin_path("chkconfig")
|
chkconfig_path = self.module.get_bin_path("chkconfig")
|
||||||
|
|
||||||
# Upstart and sysvinit
|
# Upstart and sysvinit
|
||||||
if initctl_path is not None and chkconfig_path is None:
|
if initctl_path is not None and chkconfig_path is None:
|
||||||
rc, stdout, stderr = self.module.run_command("%s --status-all 2>&1 | grep -E \"\\[ (\\+|\\-) \\]\"" % service_path, use_unsafe_shell=True)
|
rc, stdout, stderr = self.module.run_command("%s --status-all 2>&1 | grep -E \"\\[ (\\+|\\-) \\]\"" % service_path, use_unsafe_shell=True)
|
||||||
@ -91,25 +92,23 @@ class ServiceScanService(BaseService):
|
|||||||
# RH sysvinit
|
# RH sysvinit
|
||||||
elif chkconfig_path is not None:
|
elif chkconfig_path is not None:
|
||||||
#print '%s --status-all | grep -E "is (running|stopped)"' % service_path
|
#print '%s --status-all | grep -E "is (running|stopped)"' % service_path
|
||||||
rc, stdout, stderr = self.module.run_command('%s --status-all | grep -E "dead|is (running|stopped)"' % service_path, use_unsafe_shell=True)
|
p = re.compile('(?P<service>.*?)\s+[0-9]:(?P<rl0>on|off)\s+[0-9]:(?P<rl1>on|off)\s+[0-9]:(?P<rl2>on|off)\s+[0-9]:(?P<rl3>on|off)\s+[0-9]:(?P<rl4>on|off)\s+[0-9]:(?P<rl5>on|off)\s+[0-9]:(?P<rl6>on|off)')
|
||||||
for line in stdout.split("\n"):
|
rc, stdout, stderr = self.module.run_command('%s' % chkconfig_path, use_unsafe_shell=True)
|
||||||
line_data = line.split()
|
for line in stdout.split('\n'):
|
||||||
if re.match(".+\(pid.+[0-9]+\).+is running", line) is not None and len(line_data) == 5:
|
m = p.match(line)
|
||||||
service_name = line_data[0]
|
if m:
|
||||||
service_pid = line_data[2].replace(")","")
|
service_name = m.group('service')
|
||||||
service_state = "running"
|
service_state = 'stopped'
|
||||||
elif len(line_data) > 2 and line_data[1] == "dead":
|
if m.group('rl3') == 'on':
|
||||||
service_name = line_data[0]
|
rc, stdout, stderr = self.module.run_command('%s %s status' % (service_path, service_name), use_unsafe_shell=True)
|
||||||
service_pid = None
|
service_state = rc
|
||||||
service_state = "dead"
|
if rc in (0,):
|
||||||
elif len(line_data) == 3:
|
service_state = 'running'
|
||||||
service_name = line_data[0]
|
#elif rc in (1,3):
|
||||||
service_pid = None # NOQA
|
else:
|
||||||
service_state = "stopped"
|
service_state = 'stopped'
|
||||||
else:
|
service_data = {"name": service_name, "state": service_state, "source": "sysv"}
|
||||||
continue
|
services.append(service_data)
|
||||||
service_data = {"name": service_name, "state": service_state, "source": "sysv"}
|
|
||||||
services.append(service_data)
|
|
||||||
# rc, stdout, stderr = self.module.run_command("%s --list" % chkconfig_path)
|
# rc, stdout, stderr = self.module.run_command("%s --list" % chkconfig_path)
|
||||||
# Do something with chkconfig status
|
# Do something with chkconfig status
|
||||||
return services
|
return services
|
||||||
|
Loading…
Reference in New Issue
Block a user