1 |
root |
1.1 |
#! perl |
2 |
|
|
|
3 |
|
|
# restart server when certain resource limits are exceeded |
4 |
|
|
|
5 |
|
|
our $MAX_VMSIZE = $cf::CFG{checkrusage}{vmsize} || 1_000_000_000; |
6 |
|
|
|
7 |
|
|
$^O eq "linux" or die "only linux supported right now.\n"; |
8 |
|
|
|
9 |
|
|
Event->timer ( |
10 |
|
|
reentrant => 0, |
11 |
|
|
data => cf::WF_AUTOCANCEL, |
12 |
root |
1.2 |
interval => 10, |
13 |
|
|
after => 10, |
14 |
root |
1.1 |
cb => sub { |
15 |
|
|
open my $fh, "</proc/self/stat" |
16 |
|
|
or return; |
17 |
|
|
|
18 |
|
|
sysread $fh, my $stat, 4096; # only a single line |
19 |
|
|
my $vmsize = (split / /, $stat)[22]; |
20 |
|
|
|
21 |
root |
1.3 |
cf::cleanup "memory usage growing high, server would run out of memory soon", 0 |
22 |
|
|
if $vmsize >= $MAX_VMSIZE; |
23 |
root |
1.1 |
}, |
24 |
|
|
); |