From b7d49c50528c24452f98a5272bd4e790a1b1c856 Mon Sep 17 00:00:00 2001 From: rallytime Date: Tue, 21 Jun 2016 14:11:23 -0600 Subject: [PATCH] Handle child PIDs differently depending on the availability of psutils Fixes #34043 --- salt/modules/saltutil.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/salt/modules/saltutil.py b/salt/modules/saltutil.py index 394da2d786..157f4b85a0 100644 --- a/salt/modules/saltutil.py +++ b/salt/modules/saltutil.py @@ -51,7 +51,12 @@ import salt.utils.event import salt.utils.url import salt.transport import salt.wheel -import salt.utils.psutil_compat as psutil + +HAS_PSUTIL = True +try: + import salt.utils.psutil_compat +except ImportError: + HAS_PSUTIL = False from salt.exceptions import ( SaltReqTimeoutError, SaltRenderError, CommandExecutionError, SaltInvocationError @@ -855,12 +860,20 @@ def signal_job(jid, sig): salt '*' saltutil.signal_job 15 ''' + if HAS_PSUTIL is False: + log.warning('saltutil.signal job called, but psutil is not installed. ' + 'Install psutil to ensure more reliable and accurate PID ' + 'management.') for data in running(): if data['jid'] == jid: try: - for proc in psutil.Process(pid=data['pid']).children(recursive=True): - proc.send_signal(sig) + if HAS_PSUTIL: + for proc in salt.utils.psutil_compat.Process(pid=data['pid']).children(recursive=True): + proc.send_signal(sig) os.kill(int(data['pid']), sig) + if HAS_PSUTIL is False and 'child_pids' in data: + for pid in data['child_pids']: + os.kill(int(pid), sig) return 'Signal {0} sent to job {1} at pid {2}'.format( int(sig), jid,