221
'double' => 32
222
);
223
224
+# Used to set the maximum load that we will still respond to gitweb queries.
225
+# If server load exceed this value then return "503 server busy" error.
226
+# If gitweb cannot determined server load, it is taken to be 0.
227
+# Leave it undefined (or set to 'undef') to turn off load checking.
228
+our $maxload = 300;
229
+
230
# You define site-wide feature defaults here; override them with
231
# $GITWEB_CONFIG as necessary.
232
our %feature = (
557
do $GITWEB_CONFIG_SYSTEM if -e $GITWEB_CONFIG_SYSTEM;
558
}
559
560
+# Get loadavg of system, to compare against $maxload.
561
+# Currently it requires '/proc/loadavg' present to get loadavg;
562
+# if it is not present it returns 0, which means no load checking.
563
+sub get_loadavg {
564
+ if( -e '/proc/loadavg' ){
565
+ open my $fd, '<', '/proc/loadavg'
566
+ or return 0;
567
+ my @load = split(/\s+/, scalar <$fd>);
568
+ close $fd;
569
+
570
+ # The first three columns measure CPU and IO utilization of the last one,
571
+ # five, and 10 minute periods. The fourth column shows the number of
572
+ # currently running processes and the total number of processes in the m/n
573
+ # format. The last column displays the last process ID used.
574
+ return $load[0] || 0;
575
+ }
576
+ # additional checks for load average should go here for things that don't export
577
+ # /proc/loadavg
578
+
579
+ return 0;
580
+}
581
+
582
# version of the core git binary
583
our $git_version = qx("$GIT" --version) =~ m/git version (.*)$/ ? $1 : "unknown";
584
$number_of_git_cmds++;
585
586
$projects_list ||= $projectroot;
587
588
+if (defined $maxload && get_loadavg() > $maxload) {
589
+ die_error(503, "The load average on the server is too high");
590
+}
591
+
592
# ======================================================================
593
# input validation and dispatch
594
3360
}
3361
3362
print qq!<script type="text/javascript" src="$javascript"></script>\n!;
3331
- if ($action eq 'blame_incremental') {
3363
+ if (defined $action &&
3364
+ $action eq 'blame_incremental') {
3365
print qq!<script type="text/javascript">\n!.
3366
qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!.
3367
qq! "!. href() .qq!");\n!.
3387
# 500: The server isn't configured properly, or
3388
# an internal error occurred (e.g. failed assertions caused by bugs), or
3389
# an unknown error occurred (e.g. the git binary died unexpectedly).
3390
+# 503: The server is currently unavailable (because it is overloaded,
3391
+# or down for maintenance). Generally, this is a temporary state.
3392
sub die_error {
3393
my $status = shift || 500;
3394
my $error = shift || "Internal server error";
3395
3361
- my %http_responses = (400 => '400 Bad Request',
3362
- 403 => '403 Forbidden',
3363
- 404 => '404 Not Found',
3364
- 500 => '500 Internal Server Error');
3396
+ my %http_responses = (
3397
+ 400 => '400 Bad Request',
3398
+ 403 => '403 Forbidden',
3399
+ 404 => '404 Not Found',
3400
+ 500 => '500 Internal Server Error',
3401
+ 503 => '503 Service Unavailable',
3402
+ );
3403
git_header_html($http_responses{$status});
3404
print <<EOF;
3405
<div class="page_body">