From 28759e9f2019b472e00d8ee73ec91ad586a6e7ee Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Fri, 24 Jul 2015 12:06:02 -0400 Subject: [PATCH] Use psutil to find the right job to TERM * When using proot use psutil to find the ansible child process and issue the SIGTERM to instead of the proot process --- awx/main/tasks.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/awx/main/tasks.py b/awx/main/tasks.py index da798a59f2..e168150168 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -23,6 +23,7 @@ import uuid from distutils.version import LooseVersion as Version import dateutil.parser import yaml +import psutil # Pexpect import pexpect @@ -432,7 +433,16 @@ class BaseTask(Task): instance = self.update_model(instance.pk) if instance.cancel_flag: try: - os.kill(child.pid, signal.SIGINT) + if settings.AWX_PROOT_ENABLED: + main_proc = psutil.Process(pid=child.pid) + if hasattr(main_proc, "children"): + child_procs = main_proc.children(recursive=False) + else: + child_procs = main_proc.get_children(recursive=False) + for child_proc in child_procs: + os.kill(child_proc.pid, signal.SIGTERM) + else: + os.kill(child.pid, signal.SIGTERM) time.sleep(3) canceled = True except OSError: