How to make VPS/Server Auto Restart Apache when high-load

When you run a Web server, if the site has high traffic makes high load were extended VPS may lead to bottlenecks caused VPS deactivated.

To get around this you can install one script running 5 minutes / times to check VPS load was high or not, if there will automatically restart Apache.

Step 1: Create a file check

cd / usr / local /
mkdir auto
cd auto
nano w restart.sh

Paste the following script:

#! / bin / sh
check = cat / proc / loadavg | sed 's /\./ /' | awk '{print $ 1}'

if [$ check -gt 5] // filled 5 for VPS 512MB Ram, Ram 10 for 1GB, 2GB Ram 20
then
/etc/init.d/httpd restart
fi

Save the file, and chmod the script to 755

chmod 755 restart.sh

Step 2: Create a cron file

cd ~
cd /etc/cron.d
nano w auto_restart

Paste the following script:

* / 5 * root * /usr/local/auto/restart.sh> / dev / null 2> & 1

Save the cron file to complete.

Leave a Reply

Your email address will not be published.