protect server from high load
Bellow is a bash script that will save you a lot of energy and headaches when your server gets a high load. For instance if some of your clients / websites is going in an infinite loop because of a php programming bug it’s not worth waiting until your server crashes, you can use the script bellow to restart apache and all the php-cgi processes. (I use fastcgi on my server)
#!/bin/bash
MAXLOAD=”5″
L05=”$(uptime | gawk -F”load average: ” ‘{ print $2 }’ | gawk -F”, ” ‘{ print $1 }’)”
if [ $(echo “$L05 > $MAXLOAD”|bc) -eq 1 ]
then
unlink /tmp/message.txt
MESAJ=”/tmp/message.txt”
echo “I have restarted apache and all php-cgi processes” >> $MESAJ
/bin/mail -s “load mare $L05” “[email protected]” < $MESAJ
kill -9 `ps -ef |grep php-cgi |grep -v grep | awk '{print $2}'`
/etc/init.d/httpd restart
fi