Use a proper subprocess for conf test instead of dirty os.system + store errors if there are

This commit is contained in:
Alexandre Aubin 2019-11-07 12:25:19 +01:00
parent 5d46f3ef88
commit acba0c4a10

View file

@ -334,8 +334,17 @@ def service_status(names=[]):
# 'test-status' is an optional field to test the status of the service using a custom command # 'test-status' is an optional field to test the status of the service using a custom command
if "test-conf" in services[name]: if "test-conf" in services[name]:
conf = os.system(services[name]["test-conf"] + " &>/dev/null") p = subprocess.Popen(services[name]["test-conf"],
result[name]["configuration"] = "valid" if conf == 0 else "broken" shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
out, _ = p.communicate()
if p.returncode == 0:
result[name]["configuration"] = "valid"
else:
result[name]["configuration"] = "broken"
result[name]["configuration-details"] = out.strip().split("\n")
if len(names) == 1: if len(names) == 1:
return result[names[0]] return result[names[0]]