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)
delta:~ root# cat httpdcheck
if [ ! "$(pidof httpd)" ]
echo "Could not find pid of httpd - restarting"
service httpd restart
echo "Found pid of httpd - NO need to restart"
When testing, I did service httpd stop and waited 5 minutes and I received the email : could not find it, restarting. But when I go to the web site in browser it remains down. I have to login to ssh and do service httpd start manually to really load it.
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?
delta:~ root# ./httpdcheck
Could not find pid of httpd - restarting
Stopping httpd: [FAILED]
Starting httpd: [ OK ]
So .. when is it going wrong? Am I forgetting something?