ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/ext/checkrusage.ext
Revision: 1.2
Committed: Thu Jan 25 03:55:01 2007 UTC (17 years, 4 months ago) by root
Branch: MAIN
Changes since 1.1: +2 -2 lines
Log Message:
added checkrusage extension

File Contents

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