diff options
Diffstat (limited to 'zuul/executor/server.py')
-rw-r--r-- | zuul/executor/server.py | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/zuul/executor/server.py b/zuul/executor/server.py index 24e93f4fe..041bc7b69 100644 --- a/zuul/executor/server.py +++ b/zuul/executor/server.py @@ -19,6 +19,7 @@ import json import logging import multiprocessing import os +import psutil import shutil import signal import shlex @@ -2117,7 +2118,9 @@ class AnsibleJob(object): def runAnsible(self, cmd, timeout, playbook, ansible_version, wrapped=True, cleanup=False): config_file = playbook.ansible_config - env_copy = os.environ.copy() + env_copy = {key: value + for key, value in os.environ.copy().items() + if not key.startswith("ZUUL_")} env_copy.update(self.ssh_agent.env) if self.ara_callbacks: env_copy['ARA_LOG_CONFIG'] = self.jobdir.logging_json @@ -2200,7 +2203,7 @@ class AnsibleJob(object): stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, - preexec_fn=os.setsid, + start_new_session=True, env=env_copy, ) @@ -2229,17 +2232,22 @@ class AnsibleJob(object): line = line[:1024].rstrip() ansible_log.debug("Ansible output: %s" % (line,)) self.log.debug("Ansible output terminated") - cpu_times = self.proc.cpu_times() - self.log.debug("Ansible cpu times: user=%.2f, system=%.2f, " - "children_user=%.2f, " - "children_system=%.2f" % - (cpu_times.user, cpu_times.system, - cpu_times.children_user, - cpu_times.children_system)) - self.cpu_times['user'] += cpu_times.user - self.cpu_times['system'] += cpu_times.system - self.cpu_times['children_user'] += cpu_times.children_user - self.cpu_times['children_system'] += cpu_times.children_system + try: + cpu_times = self.proc.cpu_times() + self.log.debug("Ansible cpu times: user=%.2f, system=%.2f, " + "children_user=%.2f, " + "children_system=%.2f" % + (cpu_times.user, cpu_times.system, + cpu_times.children_user, + cpu_times.children_system)) + self.cpu_times['user'] += cpu_times.user + self.cpu_times['system'] += cpu_times.system + self.cpu_times['children_user'] += cpu_times.children_user + self.cpu_times['children_system'] += cpu_times.children_system + except psutil.NoSuchProcess: + self.log.warn("Cannot get cpu_times for process %d. Is your" + "/proc mounted with hidepid=2" + " on an old linux kernel?", self.proc.pid) ret = self.proc.wait() self.log.debug("Ansible exit code: %s" % (ret,)) finally: |