Merge pull request #34182 from rallytime/fix-34043

Handle child PIDs differently depending on the availability of psutils
This commit is contained in:
Mike Place 2016-06-22 12:22:06 -07:00 committed by GitHub
commit 6d643cd528

View File

@ -51,7 +51,12 @@ import salt.utils.event
import salt.utils.url import salt.utils.url
import salt.transport import salt.transport
import salt.wheel 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 ( from salt.exceptions import (
SaltReqTimeoutError, SaltRenderError, CommandExecutionError, SaltInvocationError SaltReqTimeoutError, SaltRenderError, CommandExecutionError, SaltInvocationError
@ -855,12 +860,20 @@ def signal_job(jid, sig):
salt '*' saltutil.signal_job <job id> 15 salt '*' saltutil.signal_job <job id> 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(): for data in running():
if data['jid'] == jid: if data['jid'] == jid:
try: try:
for proc in psutil.Process(pid=data['pid']).children(recursive=True): if HAS_PSUTIL:
proc.send_signal(sig) for proc in salt.utils.psutil_compat.Process(pid=data['pid']).children(recursive=True):
proc.send_signal(sig)
os.kill(int(data['pid']), 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( return 'Signal {0} sent to job {1} at pid {2}'.format(
int(sig), int(sig),
jid, jid,