Knowledgebase
Knowledgebase
Loadcheck script for http overload
Posted by Will Kruss on 07 May 2021 09:15 AM
Sometimes Apache on cPanel servers can become overloaded, this can be caused by scrapers, HTTP DDOS attacks or just a general spike in traffic.

This script simply checks the load and if it's over 20 it restarts the http (Apache) service. This can help prevent extended downtime or server crashing. The following is done in SSH / Terminal.

pico /root/loadcheck.sh

Enter the contents:

check=$(cat /proc/loadavg | awk '{print $1}')

check=$( printf "%.0f" $check )

if [ "$check" -gt 50 ]; then

/usr/bin/systemctl restart httpd.service

fi

echo $check

Save and exit

chmod 755 /root/loadcheck.sh

crontab -e

Enter this as the last line:

* * * * * /root/loadcheck.sh > /dev/null 2>&1

Save and exit

(0 vote(s))
Helpful
Not helpful