mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
Merge pull request #34182 from rallytime/fix-34043
Handle child PIDs differently depending on the availability of psutils
This commit is contained in:
commit
6d643cd528
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user