1 |
root |
1.1 |
#! perl |
2 |
|
|
|
3 |
|
|
# restart server when certain resource limits are exceeded |
4 |
|
|
|
5 |
root |
1.8 |
# TODO, CONF framework? |
6 |
|
|
our $MAX_VMSIZE = $cf::CFG{checkrusage}{vmsize} || 1_000_000_000; |
7 |
root |
1.1 |
|
8 |
|
|
$^O eq "linux" or die "only linux supported right now.\n"; |
9 |
|
|
|
10 |
root |
1.6 |
our $STAT_FH; |
11 |
|
|
our $TIMER; |
12 |
|
|
|
13 |
|
|
cf::post_init { |
14 |
root |
1.7 |
cf::async_ext { |
15 |
|
|
$STAT_FH = Coro::AIO::aio_open "/proc/self/stat", IO::AIO::O_RDONLY, 0 |
16 |
|
|
or return; |
17 |
root |
1.1 |
|
18 |
root |
1.7 |
$TIMER = cf::periodic 10, sub { |
19 |
|
|
sysseek $STAT_FH, 0, 0; |
20 |
|
|
sysread $STAT_FH, my $stat, 4096; # only a single line |
21 |
|
|
my $vmsize = (split / /, $stat)[22]; |
22 |
root |
1.1 |
|
23 |
root |
1.7 |
cf::cleanup "memory usage growing high, server would run out of memory soon", 0 |
24 |
|
|
if $vmsize >= $MAX_VMSIZE; |
25 |
|
|
}; |
26 |
root |
1.6 |
}; |
27 |
root |
1.5 |
}; |