PDA

View Full Version : Server restart when load goes over 20


GlobalDC
07-29-2004, 10:38 AM
Hello, I was wondering how I would setup the server to automatically "shutdown -r now" if the server load goes over say, 20.


Thanks for your help.

Chris

Wunk
08-10-2004, 04:05 AM
That's really not a very smart thing to do, beacuse if the server has a load of 20, it's really busy doing either something or something hardwareish is wrong..

Anyways, if you REALLY wanna do that, you could make a script like:



cat /proc/loadavg | awk '{print $2}' | awk -F . {'print $1'} | while read j
do
if [ $j -gt 19 ]
then shutdown -r now
fi
done


This is just by head and untested, basically, what it does is catch the 5 minute average load (change the $2 in $1 if you want the current load), cut it down to a whole number instead of one with a decimal, and if it is greather then 19 (ie: 20), it'll issue shutdown -r now

Put this in your root user's cron (crontab -e as root):
* * * * * /path/to/script
And it'll do that check every minute..

I don't take any responsibility if anything bad happens out of this code, hehe ;)