fix
This commit is contained in:
parent
bd05de7e7f
commit
6d9025cf43
@ -47,7 +47,7 @@ The tools listed above may work at the same time on one computer.
|
|||||||
- cmdlines and
|
- cmdlines and
|
||||||
- euids
|
- euids
|
||||||
with specified regular expressions
|
with specified regular expressions
|
||||||
- If the name of the victim matches a certain regex pattern, you can run any command instead of sending the SIGTERM signal (the default corrective action) to the victim. For example:
|
- If the name or cgroup_v1 of the victim matches a certain regex pattern, you can run any command instead of sending the SIGTERM signal (the default corrective action) to the victim. For example:
|
||||||
- `sysmemctl restart foo`
|
- `sysmemctl restart foo`
|
||||||
- `kill -INT $PID` (you can override the signal sent to the victim, $PID will be replaced by the victim's PID)
|
- `kill -INT $PID` (you can override the signal sent to the victim, $PID will be replaced by the victim's PID)
|
||||||
- `kill -TERM $PID && script.sh` (in addition to sending any signal, you can run a specified script)
|
- `kill -TERM $PID && script.sh` (in addition to sending any signal, you can run a specified script)
|
||||||
@ -444,5 +444,6 @@ Please create [issues](https://github.com/hakavlad/nohang/issues). Use cases, fe
|
|||||||
- [x] Added initial support for `PSI`
|
- [x] Added initial support for `PSI`
|
||||||
- [x] Improved user input validation
|
- [x] Improved user input validation
|
||||||
- [x] Improved documentation
|
- [x] Improved documentation
|
||||||
|
- [x] Handle signals
|
||||||
|
|
||||||
- [v0.1](https://github.com/hakavlad/nohang/releases/tag/v0.1), 2018-11-23: Initial release
|
- [v0.1](https://github.com/hakavlad/nohang/releases/tag/v0.1), 2018-11-23: Initial release
|
||||||
|
45
nohang
45
nohang
@ -15,7 +15,6 @@ from sre_constants import error as invalid_re
|
|||||||
start_time = time()
|
start_time = time()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
help_mess = """usage: nohang [-h] [-v] [-t] [-p] [-c CONFIG]
|
help_mess = """usage: nohang [-h] [-v] [-t] [-p] [-c CONFIG]
|
||||||
|
|
||||||
optional arguments:
|
optional arguments:
|
||||||
@ -87,16 +86,25 @@ cgroup_v1_index, cgroup_v2_index = find_cgroup_indexes()
|
|||||||
# define functions
|
# define functions
|
||||||
|
|
||||||
|
|
||||||
|
def self_rss():
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
return pid_to_status(self_pid)[5]
|
||||||
|
|
||||||
def signal_handler(sig, frame):
|
|
||||||
log('Got signal {}'.format(sig))
|
def print_self_rss():
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
log('Self RSS: {} MiB'.format(self_rss()))
|
||||||
|
|
||||||
|
|
||||||
|
def signal_handler(signum, frame):
|
||||||
|
log('Got signal {}'.format(signum))
|
||||||
update_stat_dict_and_print(None)
|
update_stat_dict_and_print(None)
|
||||||
log('Exit')
|
log('Exit')
|
||||||
stdout.flush()
|
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def write(path, string):
|
def write(path, string):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
@ -621,9 +629,6 @@ def update_stat_dict_and_print(key):
|
|||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if key is not None:
|
if key is not None:
|
||||||
|
|
||||||
if key not in stat_dict:
|
if key not in stat_dict:
|
||||||
@ -635,7 +640,6 @@ def update_stat_dict_and_print(key):
|
|||||||
new_value = stat_dict[key] + 1
|
new_value = stat_dict[key] + 1
|
||||||
stat_dict.update({key: new_value})
|
stat_dict.update({key: new_value})
|
||||||
|
|
||||||
|
|
||||||
if print_total_stat:
|
if print_total_stat:
|
||||||
|
|
||||||
stats_msg = 'Total stat (what happened in the last {}):'.format(
|
stats_msg = 'Total stat (what happened in the last {}):'.format(
|
||||||
@ -816,7 +820,7 @@ def kib_to_mib(num):
|
|||||||
|
|
||||||
|
|
||||||
def percent(num):
|
def percent(num):
|
||||||
"""Interprete mum as percentage."""
|
"""Interprete num as percentage."""
|
||||||
return round(num * 100, 1)
|
return round(num * 100, 1)
|
||||||
|
|
||||||
|
|
||||||
@ -1194,7 +1198,6 @@ def find_victim(_print_proc_table):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
return pid, victim_badness, victim_name
|
return pid, victim_badness, victim_name
|
||||||
|
|
||||||
|
|
||||||
@ -1677,6 +1680,7 @@ def sleep_after_check_mem():
|
|||||||
|
|
||||||
sleep(t)
|
sleep(t)
|
||||||
|
|
||||||
|
|
||||||
def calculate_percent(arg_key):
|
def calculate_percent(arg_key):
|
||||||
"""
|
"""
|
||||||
parse conf dict
|
parse conf dict
|
||||||
@ -2644,10 +2648,14 @@ if not root:
|
|||||||
log('WARNING: effective UID != 0; euid={}; processes with other e'
|
log('WARNING: effective UID != 0; euid={}; processes with other e'
|
||||||
'uids will be invisible for nohang'.format(self_uid))
|
'uids will be invisible for nohang'.format(self_uid))
|
||||||
|
|
||||||
|
|
||||||
|
print_self_rss()
|
||||||
|
|
||||||
|
|
||||||
# if print_proc_table:
|
# if print_proc_table:
|
||||||
# find_victim(print_proc_table)
|
# find_victim(print_proc_table)
|
||||||
|
|
||||||
log('Monitoring started!')
|
log('Monitoring has started!')
|
||||||
|
|
||||||
stdout.flush()
|
stdout.flush()
|
||||||
|
|
||||||
@ -2670,15 +2678,10 @@ if print_mem_check_results:
|
|||||||
report0 = 0
|
report0 = 0
|
||||||
|
|
||||||
|
|
||||||
|
# handle signals
|
||||||
signal(SIGTERM, signal_handler)
|
sig_list = [SIGTERM, SIGINT, SIGQUIT, SIGHUP, SIGABRT, SIGSEGV, SIGBUS]
|
||||||
signal(SIGINT, signal_handler)
|
for signum in sig_list:
|
||||||
signal(SIGQUIT, signal_handler)
|
signal(signum, signal_handler)
|
||||||
signal(SIGHUP, signal_handler)
|
|
||||||
signal(SIGABRT, signal_handler)
|
|
||||||
signal(SIGSEGV, signal_handler)
|
|
||||||
signal(SIGBUS, signal_handler)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=Highly configurable out of memory preventer
|
Description=Highly configurable OOM prevention daemon
|
||||||
After=sysinit.target
|
After=sysinit.target
|
||||||
Documentation=man:nohang(1) https://github.com/hakavlad/nohang
|
Documentation=man:nohang(1) https://github.com/hakavlad/nohang
|
||||||
|
|
||||||
@ -7,6 +7,10 @@ Documentation=man:nohang(1) https://github.com/hakavlad/nohang
|
|||||||
ExecStart=/usr/sbin/nohang --config /etc/nohang/nohang.conf
|
ExecStart=/usr/sbin/nohang --config /etc/nohang/nohang.conf
|
||||||
Slice=nohang.slice
|
Slice=nohang.slice
|
||||||
Restart=always
|
Restart=always
|
||||||
|
KillMode=mixed
|
||||||
|
StartLimitBurst=60
|
||||||
|
StartLimitInterval=20
|
||||||
|
StartLimitIntervalSec=20
|
||||||
MemoryMax=50M
|
MemoryMax=50M
|
||||||
TasksMax=50
|
TasksMax=50
|
||||||
Nice=-20
|
Nice=-20
|
||||||
|
Loading…
Reference in New Issue
Block a user