Script to auto restart httpd and mysqld

pipsta

New member
Joined
Feb 17, 2007
Messages
3
Hi guys,

Just lately my server load has been cutting out because of the load going up to 50+, once i saw it go to 300

Im wondering if there is a script i can run via a cron job so if the server load goes up to about 5 it automatically restarts httpd or mysqld

Also is there a way to find out exactly which account is causing the high load?

Any help appreciated

Thanks
 
We've got such a script, but you'd be much better off adding more memory. That's what we did when we discovered the script was restarting http almost every time it ran (we ran it every five minutes).
Here's what we put into /etc/crontab:
Code:
*/05 * * * * root /path/to/loadmonitor
Don't forget to change the path to where you put it.

I've put the script here.

Jeff
 
Thank you Jeff this will come in very handy, I do not have too much customers and my server costs enough without having to add more ram, so i would rather use this

Thanks mate its just what i was looking for :)
 
Jeff
1st thanks, might be useful, on occasion, and Im not sure exactly why, the server load will exceed 30, this is not a normal thing, so I will modify the values to be a preventive measure if loads exceed say, 20, and check every 10 minutes, but please assist, still learning many things, so bear with me.
the name of this file can be just "loadmonitor" ?, no extension ?
upload wherever I want, set cron to run... and thats it?
thanks
Andy

We've got such a script, but you'd be much better off adding more memory. That's what we did when we discovered the script was restarting http almost every time it ran (we ran it every five minutes).
Here's what we put into /etc/crontab:
Code:
*/05 * * * * root /path/to/loadmonitor
Don't forget to change the path to where you put it.

I've put the script here.

Jeff
 
This yours? :D
do you use it yourself..... :)
any pointers on its use... :confused:
System Integrity Monitor (SIM) is written by the author(s) of R-fx Networks at: http://rfxnetworks.com To learn more about the script, go to: http://rfxnetworks.com/sim.php

Jeff, good script. It is pretty good :)

Now, pipsta and AndII wouldn't you guys want to know the real cause of the intermittent surge of CPU load?
 
Now, pipsta and AndII wouldn't you guys want to know the real cause of the intermittent surge of CPU load?
of course :)
but with two sites on a dedicated server, this doesnt happen very often, and it seems apache gets all confuseled , loads up with legitimate requests and hangs.
a simple httpd restart seems to instantly cure the situation and were back on track till, well, whenever.
having a few servers and having to learn alot to care for them after my network guy got sooo busy he just cant seem to find time to assist, so here I am , on a learning curve that wasnt planned LOL

PS
was over at http://rfxnetworks.com, they got a few nice scripts there :)
 
Last edited:
Hi Jeff,
Perhaps you can assist.
I modified loadmonitor to LOAD_WARNING="2" (testing)
added the email to send report.
put the file here,/etc/loadmonitor
Should this cron show in cron log var/log/cron ?
I modified /etc/crontab:
*/05 * * * * root /etc/loadmonitor
put it under the last line crontab
like this
# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
*/05 * * * * root /etc/loadmonitor
Did I do this correctly?
I dont see any info that its running and of course the load hasn't reached 2 as of yet
I appreciate your help! :)


We've got such a script, but you'd be much better off adding more memory. That's what we did when we discovered the script was restarting http almost every time it ran (we ran it every five minutes).
Here's what we put into /etc/crontab:
Code:
*/05 * * * * root /path/to/loadmonitor
Don't forget to change the path to where you put it.

I've put the script here.

Jeff
 
is there a better place to put the cron?
its not showing in logs as running and of course it hasnt worked for me yet.
I lowered the trip point for warning and nothing was sent and apache wasnt restarted..
 
I don't think it shows anything if it runs successfully. Try changing the script to send you an email evey time it runs, as a way to test it. Don't forget to change it back.

I don't have time to do testing myself right now; I'm leaving in less than two hours for a business meeting tomorrow in Las Vegas.

Jeff
 
good luck and have fun at your meeting, don't gamble too much LOL.
The load has exceeded the warning setting and I haven't received any mail as of yet, also I set it to restart httpd on a load of 2, eithe way it doesnt seem to function.
Im sure its the way I setup the cron and not the script
 
I don't gamble at all. I used to, but I no longer do. When I lost a lot of money in a prior business I stopped playing the high-stakes table games, and the machines don't do a thing for me anymore, now that I don't see hundreds of silver-dollars clanging into the tray :).

I was snowed in a few days but got back late last night, and I'm finally getting back to the forums now.

I know the script works for me; I don't know what else to say on that. I already explained how to change the script to send you an email so you'll know if the cronjob is even running.

Jeff
 
Snowed in...Yuk lol
Im in NY so snow is a part of life here too.
I was just asking if I had set up the cron correct and if I put loadmonitor in /etc, should that be the correct way?
Andy
 
I got back during the short period the roads were open. They closed again yesterday morning and won't be open through today.

I-15, the highway between Riverside (where I am) and Las Vegas, and I-5, the highway between Los Angeles and Northern California.

Where in NY? The city? The island? upstate?

It shouldn't matter where you put the script; I put them in their own directory under /usr/local, because to me that makes sense.

The cron looks good to me. Why not test it the way I suggested? I did when I first set it up.

Jeff
 
more upstate NY just below Syracuse
Im not sure how to get it to send an email everytime it runs, I did set the limits low so it would trip them and send me a 'warning" email , but hadn't and it did exceed the LOAD_WARNING
SERVER_NAME="srv1.myserver.net"
EMAIL_ADDRESS="[email protected]"
UP_TIME=`uptime`
#101 means no warning emails.
LOAD_WARNING="2"
HTTPD_RESTART_LOAD="5"
 
Back
Top