Results 1 to 4 of 4
-
01-10-2007, 09:44 PM #1Newbie
- Join Date
- Mar 2002
- Location
- Netherlands
- Posts
- 12
Apache auto-restart script (crontab)
Hello,
I have root ssh access to a server and we notice when doing a bash ./mysq-backup script to dump the data from the web site's databases into .sql and .tgz them that httpd goes down sometimes. That, and sometimes it seems that httpd goes down in other situations. All fine, we will figure out why. But ..
It would be nice to run a crontab to check every 15 minutes if httpd is running, if not, to restart it.
Right now I when I notice the site is down I log into the ssh as root and type: service httpd restart. If it is up it will then first stop it, and restart it. I can look at the screen and see it happen, so I feel pretty safe doing this. One of my concerns is that when I am not at the screen and it stays down .. I do not notice this and downtime increases. And we don't want to just crontab service httpd restart, so a bash script to check for the pid and restart if it down .. would be nice.
I thought this would work:
(chmod 755 httpdcheck)
Code:delta:~ root# cat httpdcheck #!/bin/bash if [ ! "$(pidof httpd)" ] then echo "Could not find pid of httpd - restarting" service httpd restart else echo "Found pid of httpd - NO need to restart" fi delta:~ root#
Code:delta:~ root# crontab -l */5 * * * * /root/httpdcheck | mail my@email delta:~ root#
Manually loading btw .. shows it works as bash script just fine, so I dont't know why it won't work when run from cron?
Code:delta:~ root# ./httpdcheck Could not find pid of httpd - restarting Stopping httpd: [FAILED] Starting httpd: [ OK ] delta:~ root#
Hopefully someone knows.
-
01-10-2007, 09:54 PM #2Eternal Member
- Join Date
- Dec 2004
- Location
- New York, NY
- Posts
- 10,710
Don't know if it'll help but maybe try specifying the path;
service httpd restart
do
/sbin/service httpd restart
-
01-10-2007, 09:59 PM #3Newbie
- Join Date
- Mar 2002
- Location
- Netherlands
- Posts
- 12
That was exactly it. Thank you!
-
01-11-2007, 06:27 PM #4Web Hosting Guru
- Join Date
- Jan 2007
- Posts
- 254
try this:
http://www.rfxnetworks.com/sim.phpServer Surgeon George
http://www.serversurgeon.com
Linux, BSD and Windows Administration Services
Toll Free US 877-378-7436 International +1-213-291-9191