Improve customizing soft corrective actions: add @SOFT_ACTION_RE_CGROUP_V2
This commit is contained in:
parent
e94ac4cf02
commit
1b24be5359
@ -597,12 +597,12 @@ def check_config():
|
|||||||
else:
|
else:
|
||||||
log(' (not set)')
|
log(' (not set)')
|
||||||
|
|
||||||
log('\n8. Customize corrective actions')
|
log('\n8. Customize soft corrective actions')
|
||||||
|
|
||||||
if len(soft_actions_list) > 0:
|
if len(soft_actions_list) > 0:
|
||||||
log(' Match by: regexp: command: ')
|
log(' Match by: regexp: command: ')
|
||||||
for i in soft_actions_list:
|
for i in soft_actions_list:
|
||||||
log(' {} {} {}'.format(i[0], i[1], i[2]))
|
log(' {} {} {}'.format(i[0].ljust(10), i[1].ljust(12), i[2]))
|
||||||
else:
|
else:
|
||||||
log(' (not set)')
|
log(' (not set)')
|
||||||
|
|
||||||
@ -2295,19 +2295,25 @@ def implement_corrective_action(
|
|||||||
if soft_actions and threshold is SIGTERM:
|
if 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)
|
||||||
service = ''
|
cgroup_v2 = pid_to_cgroup_v2(pid)
|
||||||
cgroup_v1_tail = cgroup_v1.rpartition('/')[2]
|
|
||||||
if cgroup_v1_tail.endswith('.service'):
|
|
||||||
service = cgroup_v1_tail
|
|
||||||
for i in soft_actions_list:
|
for i in soft_actions_list:
|
||||||
unit = i[0]
|
unit = i[0]
|
||||||
if unit == 'name':
|
if unit == 'name':
|
||||||
u = name
|
u = name
|
||||||
else:
|
elif unit == 'cgroup_v1':
|
||||||
u = cgroup_v1
|
u = cgroup_v1
|
||||||
|
service = ''
|
||||||
|
cgroup_v1_tail = cgroup_v1.rpartition('/')[2]
|
||||||
|
if cgroup_v1_tail.endswith('.service'):
|
||||||
|
service = cgroup_v1_tail
|
||||||
|
else:
|
||||||
|
u = cgroup_v2
|
||||||
|
service = ''
|
||||||
|
cgroup_v2_tail = cgroup_v2.rpartition('/')[2]
|
||||||
|
if cgroup_v2_tail.endswith('.service'):
|
||||||
|
service = cgroup_v2_tail
|
||||||
regexp = i[1]
|
regexp = i[1]
|
||||||
command = i[2]
|
command = i[2]
|
||||||
|
|
||||||
if search(regexp, u) is not None:
|
if search(regexp, u) is not None:
|
||||||
log("Regexp '{}' matches with {} '{}'".format(
|
log("Regexp '{}' matches with {} '{}'".format(
|
||||||
regexp, unit, u))
|
regexp, unit, u))
|
||||||
@ -2824,10 +2830,7 @@ badness_adj_re_uid_list = []
|
|||||||
badness_adj_re_cgroup_v1_list = []
|
badness_adj_re_cgroup_v1_list = []
|
||||||
badness_adj_re_cgroup_v2_list = []
|
badness_adj_re_cgroup_v2_list = []
|
||||||
badness_adj_re_realpath_list = []
|
badness_adj_re_realpath_list = []
|
||||||
|
|
||||||
badness_adj_re_cwd_list = []
|
badness_adj_re_cwd_list = []
|
||||||
|
|
||||||
|
|
||||||
soft_actions_list = []
|
soft_actions_list = []
|
||||||
|
|
||||||
# separator for optional parameters (that starts with @)
|
# separator for optional parameters (that starts with @)
|
||||||
@ -2846,8 +2849,10 @@ try:
|
|||||||
|
|
||||||
etc = line.startswith('@SOFT_ACTION_RE_NAME')
|
etc = line.startswith('@SOFT_ACTION_RE_NAME')
|
||||||
etc2 = line.startswith('@SOFT_ACTION_RE_CGROUP_V1')
|
etc2 = line.startswith('@SOFT_ACTION_RE_CGROUP_V1')
|
||||||
|
etc2_2 = line.startswith('@SOFT_ACTION_RE_CGROUP_V2')
|
||||||
|
|
||||||
if not a and not b and not c and not d and not etc and not etc2:
|
if (not a and not b and not c and not d and not etc and
|
||||||
|
not etc2 and not etc2_2):
|
||||||
a = line.partition('=')
|
a = line.partition('=')
|
||||||
|
|
||||||
key = a[0].strip()
|
key = a[0].strip()
|
||||||
@ -2891,6 +2896,22 @@ try:
|
|||||||
|
|
||||||
soft_actions_list.append(zzz)
|
soft_actions_list.append(zzz)
|
||||||
|
|
||||||
|
if etc2_2:
|
||||||
|
|
||||||
|
a = line.partition('@SOFT_ACTION_RE_CGROUP_V2')[
|
||||||
|
2].partition(opt_separator)
|
||||||
|
|
||||||
|
a1 = 'cgroup_v2'
|
||||||
|
|
||||||
|
a2 = a[0].strip()
|
||||||
|
valid_re(a2)
|
||||||
|
|
||||||
|
a3 = a[2].strip()
|
||||||
|
|
||||||
|
zzz = (a1, a2, a3)
|
||||||
|
|
||||||
|
soft_actions_list.append(zzz)
|
||||||
|
|
||||||
if line.startswith('@BADNESS_ADJ_RE_NAME'):
|
if line.startswith('@BADNESS_ADJ_RE_NAME'):
|
||||||
a = line.partition('@BADNESS_ADJ_RE_NAME')[2].strip(
|
a = line.partition('@BADNESS_ADJ_RE_NAME')[2].strip(
|
||||||
' \n').partition(opt_separator)
|
' \n').partition(opt_separator)
|
||||||
|
@ -414,18 +414,15 @@ ignore_positive_oom_score_adj = False
|
|||||||
|
|
||||||
8. Customize soft corrective actions
|
8. Customize soft corrective actions
|
||||||
|
|
||||||
TODO: docs
|
Run the command instead of sending a signal with at soft corrective action
|
||||||
|
if the victim's name or cgroup matches the regular expression.
|
||||||
|
|
||||||
Syntax:
|
Syntax:
|
||||||
KEY REGEXP SEPARATOR COMMAND
|
KEY REGEXP SEPARATOR COMMAND
|
||||||
|
|
||||||
@SOFT_ACTION_RE_NAME ^foo$ /// kill -KILL $PID
|
@SOFT_ACTION_RE_NAME ^foo$ /// kill -USR1 $PID
|
||||||
@SOFT_ACTION_RE_NAME ^bash$ /// kill -9 $PID
|
|
||||||
|
|
||||||
@SOFT_ACTION_RE_CGROUP_V1 ^/system\.slice/ /// systemctl restart $SERVICE
|
@SOFT_ACTION_RE_CGROUP_V1 ^/system\.slice/ /// systemctl restart $SERVICE
|
||||||
@SOFT_ACTION_RE_CGROUP_V1 /foo\.service$ /// systemctl restart $SERVICE
|
@SOFT_ACTION_RE_CGROUP_V2 /foo\.service$ /// systemctl restart $SERVICE
|
||||||
|
|
||||||
@SOFT_ACTION_RE_NAME ^tail$ /// kill -TERM $PID
|
|
||||||
|
|
||||||
$PID will be replaced by process PID.
|
$PID will be replaced by process PID.
|
||||||
$NAME will be replaced by process name.
|
$NAME will be replaced by process name.
|
||||||
|
@ -364,18 +364,15 @@ ignore_positive_oom_score_adj = False
|
|||||||
|
|
||||||
8. Customize soft corrective actions
|
8. Customize soft corrective actions
|
||||||
|
|
||||||
TODO: docs
|
Run the command instead of sending a signal with at soft corrective action
|
||||||
|
if the victim's name or cgroup matches the regular expression.
|
||||||
|
|
||||||
Syntax:
|
Syntax:
|
||||||
KEY REGEXP SEPARATOR COMMAND
|
KEY REGEXP SEPARATOR COMMAND
|
||||||
|
|
||||||
@SOFT_ACTION_RE_NAME ^foo$ /// kill -KILL $PID
|
@SOFT_ACTION_RE_NAME ^foo$ /// kill -USR1 $PID
|
||||||
@SOFT_ACTION_RE_NAME ^bash$ /// kill -9 $PID
|
|
||||||
|
|
||||||
@SOFT_ACTION_RE_CGROUP_V1 ^/system\.slice/ /// systemctl restart $SERVICE
|
@SOFT_ACTION_RE_CGROUP_V1 ^/system\.slice/ /// systemctl restart $SERVICE
|
||||||
@SOFT_ACTION_RE_CGROUP_V1 /foo\.service$ /// systemctl restart $SERVICE
|
@SOFT_ACTION_RE_CGROUP_V2 /foo\.service$ /// systemctl restart $SERVICE
|
||||||
|
|
||||||
@SOFT_ACTION_RE_NAME ^tail$ /// kill -TERM $PID
|
|
||||||
|
|
||||||
$PID will be replaced by process PID.
|
$PID will be replaced by process PID.
|
||||||
$NAME will be replaced by process name.
|
$NAME will be replaced by process name.
|
||||||
|
Loading…
Reference in New Issue
Block a user