File: //proc/self/root/proc/self/root/scripts.20110531.215904.25158/checkmaxclients
#!/usr/bin/perl
# cpanel - checkmaxclients Copyright(c) 2010 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cpanel license. Unauthorized copying is prohibited
BEGIN { unshift @INC, '/usr/local/cpanel'; }
use strict;
use Cpanel::RcsRecord ();
use Cpanel::SafeFile ();
use Cpanel::iContact ();
use Cpanel::HttpUtils ();
use Cpanel::Hostname ();
use Cpanel::Logger ();
my $logger = Cpanel::Logger->new();
my $hostname = Cpanel::Hostname::gethostname();
my $size = ( stat('/usr/local/apache/logs/error_log') )[7];
$size = ( $size - 10000 );
if ( $size < 0 ) {
$size = 0;
}
my $maxclients = 0;
my $maxfiles = 1;
my $maxfilesline = '';
open( ERRLOG, '/usr/local/apache/logs/error_log' );
seek( ERRLOG, $size, 0 );
while (<ERRLOG>) {
if (/you probably need to rebuild Apache with a larger FD_SETSIZE/) {
print "Max Files Reached\n";
$maxfiles = 1;
$maxfilesline = $_;
last if ($maxclients);
}
if (/\[error\] server reached MaxClients setting/) {
print "MaxClients has been reached\n";
$maxclients = 1;
last if $maxfiles;
}
}
close(ERRLOG);
if ( !$maxclients ) {
exec '/scripts/checkbadconf';
exit;
}
my $httpconf = Cpanel::HttpUtils::find_httpconf();
if ( !-e $httpconf ) { $logger->die("Could not find $httpconf"); }
Cpanel::RcsRecord::rcsrecord( $httpconf, 'checkmaxclients BEGIN' );
my $httplock = Cpanel::SafeFile::safeopen( \*HTTPCONF, '+<', $httpconf );
if ( !$httplock ) {
$logger->die("Could not edit $httpconf");
}
my @THTTPCONF = <HTTPCONF>;
seek( HTTPCONF, 0, 0 );
my $problems;
foreach my $line (@THTTPCONF) {
if ( $line =~ /MaxClients[\s\t]*(\d+)/ ) {
my $maxc = $1;
if ( $maxc < 255 ) {
$maxc += 10;
$problems .= qq{Apache has reached the MaxClients limit. };
$problems .= qq{cPanel has increased the MaxClients limit to $maxc };
$problems .= qq{(10 higher).\n\n};
$problems .= qq{You may wish to suspend the user with the largest };
$problems .= qq{access log as they are generally the person using };
$problems .= qq{up all of the available connections. However, your };
$problems .= qq{should have your system admin verify this first.};
$problems .= qq{\n\nTop 3 Largest access logs\n==================\n};
$problems .= `du -s /usr/local/apache/domlogs/* |sort -rn |head -3`;
}
else {
$problems .= qq{Apache has reached the MaxClients limit. You };
$problems .= qq{should edit httpd.conf and change the MaxClients };
$problems .= qq{to something higher. cPanel normally does this };
$problems .= qq{for you, however it will not set this to a number };
$problems .= qq{above 255 since this may cause the server to };
$problems .= qq{crash/fallover. The MaxClients setting is currently };
$problems .= qq{set at $maxc\n\n};
$problems .= qq{You may wish to suspend the user with the largest };
$problems .= qq{access log as they are generally the person using };
$problems .= qq{up all of the available connections. However, your };
$problems .= qq{should have your system admin verify this first.};
$problems .= qq{\n\nTop 3 Largest access logs\n==================\n};
$problems .= `du -s /usr/local/apache/domlogs/* |sort -rn |head -3`;
}
print HTTPCONF "MaxClients $maxc\n";
print "Max Clients has been increased to $maxc\n";
}
else {
print HTTPCONF $line;
}
}
truncate( HTTPCONF, tell(HTTPCONF) );
Cpanel::SafeFile::safeclose( \*HTTPCONF, $httplock );
Cpanel::RcsRecord::rcsrecord( $httpconf, 'checkmaxclients END' );
if ( $problems ne '' ) {
print "SENT email\n";
Cpanel::iContact::icontact(
'application' => 'maxclients',
'level' => 1,
'subject' => qq{[maxclientscheck] $hostname has exceeded the MaxClients limit},
'message' => $problems,
'msgtype' => ''
);
}
if ($maxfiles) {
Cpanel::iContact::icontact(
'application' => 'maxfiles',
'level' => 1,
'subject' => qq{[maxfilescheck] Apache on $hostname has exceeded the maximum amount of open files},
'message' => $maxfilesline,
'msgtype' => ''
);
}
exec '/scripts/checkbadconf';