httpd-DSSL processes not closing, creating HUGE server loads

DrGreen

Active Member
May 5, 2004
44
0
156
Yes but it can`t have anything todo with active sites, i transfered from a celeron 2.4 with a average load of 0.60.

So it is really something else, misconfiguration or something
 

dethman

Well-Known Member
PartnerNOC
Jan 4, 2003
120
0
166
Buenos Aires, Argentina
cPanel Access Level
DataCenter Provider
i have this scripts...

yaax said:
I made few fixes in the script, like renice of this process and preventing this script from executing twice at same time:

PHP:
#!/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;
when i test...

# cat load.log
Tue Feb 1 21:25:00 ART 2005 - 4.51
Tue Feb 1 21:30:00 ART 2005 - 13.58
Tue Feb 1 21:30:00 ART 2005 - httpd stopped > stop httpd
Tue Feb 1 21:30:56 ART 2005 - after stop load=13.18
Tue Feb 1 21:31:16 ART 2005 - after stop load=9.51
Tue Feb 1 21:31:36 ART 2005 - after stop load=6.96
Tue Feb 1 21:31:56 ART 2005 - after stop load=5.05
Tue Feb 1 21:32:16 ART 2005 - after stop load=3.61
Tue Feb 1 21:32:36 ART 2005 - after stop load=2.75
Tue Feb 1 21:32:44 ART 2005 - httpd restarted > restart httpd
Tue Feb 1 21:35:00 ART 2005 - 3.43

somebody can say to me if there is some form to reset httpd instead of stopping? it or but reset httpd and by to stop it when the server load is + o - to 20 for example.
 

yaax

Well-Known Member
Jun 15, 2003
67
0
156
dethman said:
i have this scripts...



when i test...

# cat load.log
Tue Feb 1 21:25:00 ART 2005 - 4.51
Tue Feb 1 21:30:00 ART 2005 - 13.58
Tue Feb 1 21:30:00 ART 2005 - httpd stopped > stop httpd
Tue Feb 1 21:30:56 ART 2005 - after stop load=13.18
Tue Feb 1 21:31:16 ART 2005 - after stop load=9.51
Tue Feb 1 21:31:36 ART 2005 - after stop load=6.96
Tue Feb 1 21:31:56 ART 2005 - after stop load=5.05
Tue Feb 1 21:32:16 ART 2005 - after stop load=3.61
Tue Feb 1 21:32:36 ART 2005 - after stop load=2.75
Tue Feb 1 21:32:44 ART 2005 - httpd restarted > restart httpd
Tue Feb 1 21:35:00 ART 2005 - 3.43

somebody can say to me if there is some form to reset httpd instead of stopping? it or but reset httpd and by to stop it when the server load is + o - to 20 for example.

This command will restart httpd
system("/scripts/restartsrv_httpd");

You can edit this script and tweak any parameters there, as you can change first condition
if ($ld>=12) {
You can change if ($ld>=20) {
or change it as if ($ld>=18 and ld<=22) {

However I especially did so - to stop http for few minutes and then restart it - because if you only do restart - this will not fix server load - because all connections will return just in few seconds - you need exactly stop - wait until load will be low and then start it.
 

yaax

Well-Known Member
Jun 15, 2003
67
0
156
dethman said:
its true...
mmm what is the variable to change once for the service reset them, when the server load this under 8 for example?
You have there another varuable "$loadlevel=3; " - this mean what is cpu load level to start all services after they were stopped.

I think load 8 is too high level to start services, but you can do as you wish.

Actually I had some plans to extend this part of script and enter there more AI - like after start of service check them if they go up then high level again - this probably mean that low level was not low enough or httpd was not a true reason of high load - so script may do other actions- may change low load level or may stop and kill other processes.
This all depend on exact server, anyway since on my server finished problems with CPU load, I finished work on this script.
 

Radio_Head

Well-Known Member
Verifed Vendor
Feb 15, 2002
2,048
1
343
I modified the script in this way

(if you want use it don't forget to modify lines 69 and 70 with your email!

Code:
#!/usr/bin/perl


my $date = `date`;
chomp $date;

open (LOG, ">>/scripts/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;
}

###########################################################
# preventing this script from executing twice at same time
###########################################################
$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;
print "$html \n";

$ma=index($html,'e: ')+3;
$ma1=index($html,',',$ma);
$ld=substr($html,$ma,$ma1-$ma);
#print "$ld \n";

print LOG "$date - $ld\n";
#print "$date - $ld\n";

$veryhigh=0;

if ($ld>=12) { 

# send email with apache status and ps status
system("ps auxww | grep -v root | cut -c1-8,9-25,63-180 > /tmp/status.txt;mail -s \"ps Status\" youremail\@usa.net < /tmp/status.txt;rm -f /tmp/status.txt");
system("httpd fullstatus > /tmp/apstatus.txt;mail -s \"apStatus\" [email protected] < /tmp/apstatus.txt;rm -f /tmp/apstatus.txt");

        system("/usr/local/apache/bin/apachectl","stop"); 
        system("/etc/init.d/cpanel","stop"); 
        print LOG "$date - httpd stopped \n"; 
         
        if ($ld>40) { 
                $veryhigh=1; 
        } 

    $ct=0; 
    $loadlevel=2;
    
    # Con apache e cpanel services fermi attende 15 secondi (eventualmente riferma apache e cpanel)
    # e scrive su load.log lo stato
    while ($ld >= $loadlevel) { 
                
                sleep(20);
                
       if ($veryhigh>0) { 
       system("service mysql stop"); 
       system("service exim stop"); 
       $date = `date`; 
       chomp $date; 
       print LOG "$date - mysql,exim,cpanel restarted \n"; 
        } 
                 
                system("/usr/local/apache/bin/apachectl","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 after 8 sleeps of 20 seconds
                # server load doesn't go low
                # raises the loadlevel by 2 and reset $ct
                $ct=$ct+1; 
                if ($ct>8) { 
                    $loadlevel=$loadlevel+2;
                    $ct=0; 
                }
                
   } 

   

   system("/scripts/restartsrv_httpd"); 
   system("service cpanel start"); 
   
   
   if ($veryhigh>0) { 
       system("service mysql start"); 
       system("service exim start"); 
       system("service cpanel restart");
       $date = `date`; 
       chomp $date; 
       print LOG "$date - mysql,exim,cpanel restarted \n"; 
        } 
   
   
   $date = `date`; 
   chomp $date; 
   print LOG "$date - httpd restarted \n"; 
} 

close (LOG); 

exit;
 

Radio_Head

Well-Known Member
Verifed Vendor
Feb 15, 2002
2,048
1
343
another update , it should work much better and send 3 email notifications
when happens the problem


it's a BETA !

Code:
#!/usr/bin/perl

#email to send apache and ps status exactly when happens the problem
$myemail="email\@usa.net";
#server name where the script is running
$servername="domain.com";

my $date = `date`;
chomp $date;

open (LOG, ">>/scripts/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;
}

###########################################################
# preventing this script from executing twice at same time
###########################################################
$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;
print "$html \n";

$ma=index($html,'e: ')+3;
$ma1=index($html,',',$ma);
$ld=substr($html,$ma,$ma1-$ma);
#print "$ld \n";

print LOG "$date - $ld\n";
#print "$date - $ld\n";

$veryhigh=0;

 if ($ld>30) { 
                $veryhigh=1; 
        } 

if ($ld>=15) { 

# send email with apache status and ps status
system("ps auxww | grep -v root | cut -c1-8,9-25,63-180 > /tmp/status.txt;mail -s \"$servername Mymonitor ps Report 1\" $myemail < /tmp/status.txt;rm -f /tmp/status.txt");
system("ps -eo user,pid,pcpu,pmem,time,command --sort=-%cpu | grep -v grep | grep -v root | cut -c1-19,20-25,26-100 > /tmp/psstatus2.txt;mail -s \"$servername Mymonitor ps Report 2\" $myemail < /tmp/psstatus2.txt;rm -f /tmp/psstatus2.txt");
system("httpd fullstatus > /tmp/apstatus.txt;mail -s \"$servername Mymonitor Report 3\" $myemail < /tmp/apstatus.txt;rm -f /tmp/apstatus.txt");

        system("/usr/local/apache/bin/apachectl","stop"); 
        system("/etc/init.d/cpanel","stop"); 
        print LOG "$date - httpd stopped \n"; 
         
       

    $ct=0; 
    $ct2=0;
    $loadlevel=2;
    
    # With apache and cpanel stopped wait for 20 secs for new loadlevel and update load.log
    while ($ld >= $loadlevel) { 
                
       sleep(20);
                
       if ($veryhigh>0) 
       { 
       $ct2=$ct2+1;	
       if ($ct<2) { 
       system("service mysql stop"); 
       system("service exim stop"); 
       $date = `date`; 
       chomp $date; 
       print LOG "$date - mysql,exim STOPPED \n"; 
       }
       } 
                 
                # try to stop again apache
                system("/usr/local/apache/bin/apachectl","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 after 8 sleeps of 20 seconds
                # server load doesn't go low
                # raises the loadlevel by 2 and reset $ct
                $ct=$ct+1; 
                if ($ct>8) { 
                    $loadlevel=$loadlevel+2;
                    $ct=0; 
                }
                
   } 

   
   # RESTART ALL
   system("/scripts/restartsrv_httpd"); 
   system("service cpanel restart"); 
   
   
   
   if ($veryhigh>0) { 
       system("service mysql restart"); 
       system("service exim restart");        
       $date = `date`; 
       chomp $date; 
       print LOG "$date - MySql,Exim restarted \n"; 
        } 
   
   $date = `date`; 
   chomp $date; 
   print LOG "$date - httpd and Cpanel restarted \n"; 
   
   
} 

close (LOG); 

exit;
 
Last edited:

yaax

Well-Known Member
Jun 15, 2003
67
0
156
I have modified and updated this script to restart courier pop3 server and kill all CPanel php processes which are frequently staying in memory and usually also using a lot of CPU.
Also I modified to send one email with 4 reports - with top, mytop - MySQL top, ps and apache status - all in one email.

Code:
#!/usr/bin/perl

system "/usr/bin/renice +20 -p $$ >/dev/null 2>&1";

my $date = `date`;
chomp $date;

#email to send apache and ps status exactly when happens the problem
$myemail="user\@yourdomain.com";
#server name where the script is running
$servername="yourservername";

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>=14) {
        # send email with apache status and ps and top and mytop status
        my $topst= `top -b -n1`;
        my $psst= `ps -eo user,pid,pcpu,pmem,time,nice,etime,command --sort=-%cpu`;
        my $apst= `httpd fullstatus | grep -v '\\.\\.\\.\\.'`;
        my $mytopst= `mytop -b`;
        $pasl="-------------------------------------------------------------------\n";

        $str= "Date: $date\n TOP commad report: \n $topst \n $pasl \n MyTop command report: \n $mytopst \n $pasl";
        $str= $str . " PS command report: \n $psst \n $pasl Apache Status report:\n $apst";

        open (ST, ">./laststatus.txt");

        print ST $str;

        close(ST);

        system("mail -s \"Mymonitor Report on $servername \" $myemail < ./laststatus.txt");

        system("/usr/local/apache/bin/apachectl","stop");
        system("/etc/init.d/cpanel","stop");
        print LOG "$date - httpd stopped \n";
        if ($ld>14) {
                $veryhigh=1;
        }

    $ct=0;
    $loadlevel=4;
    while ($ld >= $loadlevel) {
                sleep(20);
                system("/usr/local/apache/bin/apachectl","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 "/usr/bin/renice 0 -p $$ >/dev/null 2>&1";

   if ($veryhigh>0) {
        system("/scripts/restartsrv_mysql");
        system("/scripts/restartsrv_exim");
        # kill all dead processes from CPanel php
        system("killall -9 /usr/local/cpanel/3rdparty/bin/php");
        system("/etc/init.d/cpanel","restart");
        # restart courier pop3 and imap server
        system("/scripts/restartsrv_courier"); 
        $date = `date`;
        chomp $date;
        print LOG "$date - mysql,exim,cpanel,courier restarted \n";
   }

   system("/scripts/restartsrv_httpd");
   $date = `date`;
   chomp $date;
   print LOG "$date - httpd restarted \n";
   system "/usr/bin/renice +19 -p $$ >/dev/null 2>&1";
}

close (LOG);

unlink $pidfile;

exit;
 
Last edited:

konrath

Well-Known Member
May 3, 2005
366
1
166
Brasil
yaax said:
I have modified and updated this script to restart courier pop3 server and kill all CPanel php processes which are frequently staying in memory and usually also using a lot of CPU.
Also I modified to send one email with 4 reports - with top, mytop - MySQL top, ps and apache status - all in one email.

Great !

I dont receive emails of alert but script work fine. Because? :rolleyes:
No messages in log. Only I not receive.

Thank you
Konrath
 

Sys3X

Member
Sep 26, 2007
9
0
51
I have modified and updated this script to restart courier pop3 server and kill all CPanel php processes which are frequently staying in memory and usually also using a lot of CPU.
Also I modified to send one email with 4 reports - with top, mytop - MySQL top, ps and apache status - all in one email.

Code:
#!/usr/bin/perl

system "/usr/bin/renice +20 -p $$ >/dev/null 2>&1";

my $date = `date`;
chomp $date;

#email to send apache and ps status exactly when happens the problem
$myemail="user\@yourdomain.com";
#server name where the script is running
$servername="yourservername";

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>=14) {
        # send email with apache status and ps and top and mytop status
        my $topst= `top -b -n1`;
        my $psst= `ps -eo user,pid,pcpu,pmem,time,nice,etime,command --sort=-%cpu`;
        my $apst= `httpd fullstatus | grep -v '\\.\\.\\.\\.'`;
        my $mytopst= `mytop -b`;
        $pasl="-------------------------------------------------------------------\n";

        $str= "Date: $date\n TOP commad report: \n $topst \n $pasl \n MyTop command report: \n $mytopst \n $pasl";
        $str= $str . " PS command report: \n $psst \n $pasl Apache Status report:\n $apst";

        open (ST, ">./laststatus.txt");

        print ST $str;

        close(ST);

        system("mail -s \"Mymonitor Report on $servername \" $myemail < ./laststatus.txt");

        system("/usr/local/apache/bin/apachectl","stop");
        system("/etc/init.d/cpanel","stop");
        print LOG "$date - httpd stopped \n";
        if ($ld>14) {
                $veryhigh=1;
        }

    $ct=0;
    $loadlevel=4;
    while ($ld >= $loadlevel) {
                sleep(20);
                system("/usr/local/apache/bin/apachectl","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 "/usr/bin/renice 0 -p $$ >/dev/null 2>&1";

   if ($veryhigh>0) {
        system("/scripts/restartsrv_mysql");
        system("/scripts/restartsrv_exim");
        # kill all dead processes from CPanel php
        system("killall -9 /usr/local/cpanel/3rdparty/bin/php");
        system("/etc/init.d/cpanel","restart");
        # restart courier pop3 and imap server
        system("/scripts/restartsrv_courier"); 
        $date = `date`;
        chomp $date;
        print LOG "$date - mysql,exim,cpanel,courier restarted \n";
   }

   system("/scripts/restartsrv_httpd");
   $date = `date`;
   chomp $date;
   print LOG "$date - httpd restarted \n";
   system "/usr/bin/renice +19 -p $$ >/dev/null 2>&1";
}

close (LOG);

unlink $pidfile;

exit;

Please, tell me, how to setup and manage this script?
 

nithintou

Member
Dec 22, 2006
21
0
151
cPanel Access Level
Root Administrator
Please do not use this script.All it does is keep restarting unrelated services (even services which have nothing to cause a load).

What you should be doing is investigating what is causing the load spike with which service and finding ways to resolve it. And if you can't do it find someone experienced with cPanel servers who can.Restarting a 100 services every other minute isn't a solution to anything.

.
 
Last edited:

nixell

Active Member
Sep 24, 2007
29
0
51
Please do not use this script.All it does is keep restarting unrelated services (even services which have nothing to cause a load).

What you should be doing is investigating what is causing the load spike with which service and finding ways to resolve it. And if you can't do it find someone experienced with cPanel servers who can.Restarting a 100 services every other minute isn't a solution to anything.

.
I agree with you. there any solution?
 

DigitalN

Well-Known Member
Sep 23, 2004
419
1
168
Do you guys have mod_security installed?

I've seen these issues with 1 bad rule in mod_sec cause this, (usually POST checks) try disabling it to see if it's that first of the bat, then go through those rules, the regexes that you can copy down from places can cause these issues.
 

salubrium

Member
Jun 11, 2003
14
0
151
Sydney
cPanel Access Level
Root Administrator
That script is ugly

That script is ugly - it's the way a Microsoft admin would deal with things.

I have also seen mod_sec rules causing some bad load times. Apache 1.3 regex engine is very slow, so if you try and enable all rules from Gotroot then you are going to run into load issues. In saying that, I don't believe that's the problem.

I believe the recent Cpanel updates in Nov 2007 (remember this thread began in 2004/5) have broken something in /usr/local/cpanel/bin/apache_conf_distiller which is supposed to keep your Apache config settings.. well I can tell you all of mine were dropped for some stupid CPanel defaults and stuffed a lot of things up for me.

After spending some time first implementing mod_evasive, re-enabling all of my mod_sec rules, reenabling RLimits for memory and cpu, I was still getting the issue (though to a slightly lesser degree) I managed to fix it once and for all by changing the MaxRequestsPerChild - something that has bitten me once before, especially if you run Apache on Windows.

For whatever dumb reason, the default that Cpanel sets is 0 - which means each child that is spawned will never die, serving unlimited requests and eventually it seems we run into a memory crisis in Apache which Linux tries to handle by putting into Swap, causing massive I/O wait times and putting your load through the roof until there's no more physical or virtual memory and something crashes Apache or is restarted by PRM or the server is rebooted.

Changing MaxRequestsPerChild to somewhere between 200-500 generally fixes any of the memory problems I have seen with Apache. God knows why it took me a day and a half to remember this. Don't set it too low or Apache would continuosly have to kill existing and restart new child processes, slowing things down a bit.

From Apache website
The MaxRequestsPerChild directive sets the limit on the number of requests that an individual child server process will handle. After MaxRequestsPerChild requests, the child process will die. If MaxRequestsPerChild is 0, then the process will never expire.
Different default values

Setting MaxRequestsPerChild to a non-zero limit has two beneficial effects:
it limits the amount of memory that process can consume by (accidental) memory leakage;
by giving processes a finite lifetime, it helps reduce the number of processes when the server load reduces.