Page 1 of 1

How to automatically restart httpd when overloaded

Posted: Thu Oct 20, 2016 1:41 am
by duytoi
Hello friends.

Service httpd on vps always overload, memory up to 1GB or more. It makes mysqld stop times lead to faulty

I'm using vestacp, please help me create a cron job to automatically check httpd if overloaded, it will automatically restart and thus mysqld

It as a cron job created automatically

This is my site https://sharelachuan.com

Regrads.

Duy Toi

Re: How to automatically restart httpd when overloaded

Posted: Thu Oct 20, 2016 6:47 am
by Elizine
Usually once httpd is stopped, the load drops down within 60/100 seconds so there is hardly anytime down time, but it does give you time to investigate where the issue is, especially if it happens all the time.
To install, run the following in ssh and this will pull the file from my server over to yours.

Code: Select all

cd
wget http://www.craig-edmonds.com/special-tools/loadmonitor.txt
mv /root/loadmonitor.txt /root/hsws-loadmonitor.pl
chmod 755 /root/hsws-loadmonitor.pl
Then you need to add the cron to the cron tab so that it checks your server every 60 seconds.
Follow these instructions to edit the root cron file

1. open the cron file

Code: Select all

pico /var/spool/cron/root
2. add the following line to the cron file so it runs every minute

Code: Select all

* * * * * /root/hsws-loadmonitor.pl > /dev/null 2>&1
3. restart the cron with this command

Code: Select all

/etc/init.d/crond restart
Thats it!

The only thing you need to do now is change a couple of settings within the file to set your email address.

Do the following to edit your settings.

Code: Select all

pico /root/hsws-loadmonitor.pl
This will open the file and then you only need to edit the following settings:

my $contacts – the email address to send alerts to
my $from_address – the custom name of the server so you know which server its coming from

Re: How to automatically restart httpd when overloaded

Posted: Thu Oct 20, 2016 8:14 am
by mehargags
I'm 200% sure your server is compromised, some site may be injected with malicious code.
or
your App is leaking memory and causing high load.

You should really try to find out the problem rather than restarting httpd automatically.

Re: How to automatically restart httpd when overloaded

Posted: Thu Oct 20, 2016 8:58 am
by duytoi
Thank mehargags and EliZine helped me.

I will follow up more time to figure out the cause of this situation on my server

Regards !

Duy Toi