mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Handle child PIDs differently depending on the availability of psutils
Fixes #34043
This commit is contained in:
parent
6387d1636e
commit
b7d49c5052
@ -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 <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():
|
||||
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,
|
||||
|
Loading…
Reference in New Issue
Block a user