$ct=0;
while ($ld >= 2) {
sleep(20);
system("/usr/local/apache/bin/apachectl","stop");
system("/etc/init.d/cpanel","stop");
$html = `uptime`;
$html =~ s/\n+//g;
$ma=index($html,'e: ')+3;
$ma1=index($html,',',$ma);
$ld=substr($html,$ma,$ma1-$ma);
$date = `date`;
chomp $date;
print LOG "$date - after stop load=$ld \n";
}
if ($veryhigh>0) {
system("/scripts/restartsrv_mysql");
system("/scripts/restartsrv_exim");
$date = `date`;
chomp $date;
print LOG "$date - mysql,exim,cpanel restarted \n";
}
system("/scripts/restartsrv_httpd");
system("/etc/init.d/cpanel","restart");
$date = `date`;
chomp $date;
print LOG "$date - httpd restarted \n";
}
yaax said:Then while $ld is bigger then 2, it stops apache and cpanel every 20 seconds and check again - whether load is bigger then 2 - and then exit from loop and restart all services - exim, mysql, apache and cpanel.
I did few changes, cpanel should not be stopped more then one time, if it was stooped to many times it need to restart stunnel as well after.Radio_Head said:OK clear ! Your idea could be a start point to add a lot of other checks![]()
if ($ld>=12) {
system("/usr/local/apache/bin/apachectl","stop");
system("/etc/init.d/cpanel","stop");
print LOG "$date - httpd stopped \n";
if ($ld>50) {
$veryhigh=1;
}
$ct=0;
while ($ld >= 2) {
sleep(20);
system("/usr/local/apache/bin/apachectl","stop");
#system("/etc/init.d/cpanel","stop");
$html = `uptime`;
$html =~ s/\n+//g;
$ma=index($html,'e: ')+3;
$ma1=index($html,',',$ma);
$ld=substr($html,$ma,$ma1-$ma);
$date = `date`;
chomp $date;
print LOG "$date - after stop load=$ld \n";
}
if ($veryhigh>0) {
system("/scripts/restartsrv_mysql");
system("/scripts/restartsrv_exim");
$date = `date`;
chomp $date;
print LOG "$date - mysql,exim,cpanel restarted \n";
}
system("/scripts/restartsrv_httpd");
system("/etc/init.d/cpanel","restart");
system("/usr/bin/stunnel-4.04local","/usr/local/cpanel/etc/stunnel/default/stunnel.conf");
$date = `date`;
chomp $date;
print LOG "$date - httpd restarted \n";
}
close (LOG);
exit;
yaax said:I did few changes, cpanel should not be stopped more then one time, if it was stooped to many times it need to restart stunnel as well after.
PHP:if ($ld>=12) { system("/usr/local/apache/bin/apachectl","stop"); system("/etc/init.d/cpanel","stop"); print LOG "$date - httpd stopped \n"; if ($ld>50) { $veryhigh=1; } $ct=0; while ($ld >= 2) { sleep(20); system("/usr/local/apache/bin/apachectl","stop"); #system("/etc/init.d/cpanel","stop"); $html = `uptime`; $html =~ s/\n+//g; $ma=index($html,'e: ')+3; $ma1=index($html,',',$ma); $ld=substr($html,$ma,$ma1-$ma); $date = `date`; chomp $date; print LOG "$date - after stop load=$ld \n"; } if ($veryhigh>0) { system("/scripts/restartsrv_mysql"); system("/scripts/restartsrv_exim"); $date = `date`; chomp $date; print LOG "$date - mysql,exim,cpanel restarted \n"; } system("/scripts/restartsrv_httpd"); system("/etc/init.d/cpanel","restart"); system("/usr/bin/stunnel-4.04local","/usr/local/cpanel/etc/stunnel/default/stunnel.conf"); $date = `date`; chomp $date; print LOG "$date - httpd restarted \n"; } close (LOG); exit;
I think it is just problem of overloaded servers.daWeazy said:Seems this thread went from fixing the real problem to finding a temporary solution to a problem that will always exist unless someone really finds the correct solution. I have been fighting this problem for a Month.
#!/usr/bin/perl
system "/usr/bin/renice +20 -p $$ >/dev/null 2>&1";
my $date = `date`;
chomp $date;
open (LOG, ">>./load.log") || die "Failed to open file ::$!";
if (!( -f "/usr/local/apache/logs/httpd.pid" )) {
print LOG "$date - httpd not running, exiting. \n";
close (LOG);
exit;
}
$pidfile="load.pid";
if (-e $pidfile)
{
# aha, pid file is here, but process could be dead by now
unless (open(PIDFILE,$pidfile)) {
# too dangerous to start because I can't read old PID
print LOG "$date - cannot read old pid, exiting. \n";
close (LOG);
exit 1;
}
my $oldpid=<PIDFILE>;
close PIDFILE;
# see if there is a process with such pid
if ($oldpid > 1 && kill(0,$oldpid)) {
# another proccess is running already
print LOG "$date - script already running, exiting. \n";
close (LOG);
exit 1;
} else {
# that process is long dead
print LOG "$date - found dead process $oldpid in PID file. \n";
}
}
open (PID, ">$pidfile") or die;
print PID $$;
close(PID);
my $html = `uptime`;
$html =~ s/\n+//g;
$ma=index($html,'e: ')+3;
$ma1=index($html,',',$ma);
$ld=substr($html,$ma,$ma1-$ma);
print LOG "$date - $ld\n";
$veryhigh=0;
if ($ld>=12) {
system("/usr/local/apache/bin/apachectl","stop");
system("/etc/init.d/cpanel","stop");
print LOG "$date - httpd stopped \n";
#system("/root/top.cron");
if ($ld>50) {
$veryhigh=1;
}
$ct=0;
$loadlevel=3;
while ($ld >= $loadlevel) {
sleep(20);
system("/usr/local/apache/bin/apachectl","stop");
#system("/etc/init.d/cpanel","stop");
$html = `uptime`;
$html =~ s/\n+//g;
$ma=index($html,'e: ')+3;
$ma1=index($html,',',$ma);
$ld=substr($html,$ma,$ma1-$ma);
$date = `date`;
chomp $date;
print LOG "$date - after stop load=$ld \n";
$ct=$ct+1;
if ($ct>50) {
$loadlevel=6;
}
}
# system("/scripts/restartsrv_httpd");
# $date = `date`;
# chomp $date;
# print LOG "$date - httpd restarted \n";
if ($veryhigh>0) {
system("/scripts/restartsrv_mysql");
system("/scripts/restartsrv_exim");
$date = `date`;
chomp $date;
print LOG "$date - mysql,exim,cpanel restarted \n";
}
system("/scripts/restartsrv_httpd");
system("/etc/init.d/cpanel","restart");
system("/usr/bin/stunnel-4.04local","/usr/local/cpanel/etc/stunnel/default/stunnel.conf");
$date = `date`;
chomp $date;
print LOG "$date - httpd restarted \n";
}
close (LOG);
unlink $pidfile;
exit;
updatedb process you should better disable completely by deleteing it from daily cron tab, or at least remove renice command from its script.Radio_Head said:Some consideration ;
I think that your script toghter with uptime should check also
ps (grepping for example apache , exim and other things) ,
apache processes , and mysql processes.
Infact sometime teh scripts stops apache (also with few apache processes) while I have
/usr/bin/updatedb -f NFS,SMBFS,NCPFS,PROC,DEVPTS -e /tmp,/var/tmp,/usr/tm
Only some suggestion to make it more complex and useful.
yaax said:I think it is just problem of overloaded servers.
The real solution would be only upgrade of hardware or remove some too active sites from this server.
Thats why because I cannot do 2 above steps, I need this script...
XPerties said:You are soooooooo wrong. My server has been stable for months and I have not added any new clients on it nor has any changes been made except a recent upgrade of cpanel. My loads have gone form .021 average to 39.+
All TOP shows is httpd with 391% of cpu usage.
Different servers have different problems.DrGreen said:same here bro, i just got myself a brand new box, Xeon EM64T 2.8 GHz on Centos 3.3
Done transfering this night and the load went up to 70. and higher. I really need a solution for this