Extend post_kill_exe key

- Add $SERVICE replacement in this config key value.
For example, if you set
post_kill_exe = systemctl kill -s SIGKILL $SERVICE
victim's service unit will be killed.
This commit is contained in:
Alexey Avramov 2020-06-13 03:34:56 +09:00
parent f00a394783
commit 271c04dff3

View File

@ -2387,8 +2387,8 @@ def implement_corrective_action(
dset = s1 - s2 dset = s1 - s2
if len(dset) > 0: if len(dset) > 0:
log('During the search for the victim, the processes were ' log('During the search for the victim, the next processes were'
'completed: {}'.format(dset)) ' died: {}'.format(dset))
sleep(over_sleep) sleep(over_sleep)
@ -2477,8 +2477,8 @@ def implement_corrective_action(
if victim_id in v_dict: if victim_id in v_dict:
dt = monotonic() - v_dict[victim_id]['time'] dt = monotonic() - v_dict[victim_id]['time']
if dt > max_soft_exit_time: if dt > max_soft_exit_time:
log('max_soft_exit_time (value={}s) is exceeded the victim:' log('max_soft_exit_time (value={}s) is exceeded for the victim'
' it will get SIGKILL'.format( ', hard corrective action will be applied'.format(
max_soft_exit_time)) max_soft_exit_time))
threshold = SIGKILL threshold = SIGKILL
else: else:
@ -2536,8 +2536,8 @@ def implement_corrective_action(
mp[3], mp[4], mp[5] mp[3], mp[4], mp[5]
)) ))
soft_match = False if (threshold is SIGKILL and post_kill_exe != '') or (
if soft_actions and threshold is SIGTERM: soft_actions and threshold is SIGTERM):
name = pid_to_name(pid) name = pid_to_name(pid)
cgroup_v1 = pid_to_cgroup_v1(pid) cgroup_v1 = pid_to_cgroup_v1(pid)
@ -2558,6 +2558,10 @@ def implement_corrective_action(
else: else:
service = '' service = ''
soft_match = False
if soft_actions and threshold is SIGTERM:
for i in soft_actions_list: for i in soft_actions_list:
unit = i[0] unit = i[0]
if unit == 'name': if unit == 'name':
@ -2718,12 +2722,9 @@ def implement_corrective_action(
round(ma_mib, 1), round(sf_mib, 1))) round(ma_mib, 1), round(sf_mib, 1)))
if threshold is SIGKILL and post_kill_exe != '': if threshold is SIGKILL and post_kill_exe != '':
log('Executing post_kill_exe: {}'.format(post_kill_exe))
cmd = post_kill_exe.replace('$PID', pid).replace( cmd = post_kill_exe.replace('$PID', pid).replace(
'$NAME', pid_to_name(pid)) '$NAME', name).replace('$SERVICE', service)
log('Execute post_kill_exe')
start_thread(exe, cmd) start_thread(exe, cmd)
if post_action_gui_notifications: if post_action_gui_notifications: