Auto Restart apache when connection is high

In some situations, ¬†our web server receive too many connections. The number is much higher than normal, that could be an issue with our code, or we are being attack. While waiting to find a solution, we need a solution to keep the service running. The easiest solution is to restart our web server when it’s go over our limit. We’ll keep the log what the server is running, then restart the server. Later on we can see our log and do the fine tuning.

cnt=`ps -Af | grep apache2 | grep -v rotatelogs | grep -v grep | wc -l`
now=`date +%Y-%m-%d_%H-%M`

# change the 100 below to something meaningful to your server
if [ $cnt -ge 100 ]
wget -q -O /root/apache_status_$now http://localhost/server-status
apachectl restart


Leave a Reply

Your email address will not be published. Required fields are marked *