labrocca
Verified User
- Joined
- Mar 12, 2006
- Messages
- 130
Occassionally my Apache locks up from reaching max connections while under a DDOS attack or other various problems. I created a cron job that checks if Apache is running or if it's processes are high. It then restarts Apache and sends me a notifcation email. Here is the problem. It doesn't work.
This is the script.
The script itself works as I get notification emails but for some reason the httpd start/restart doesn't work from cron. It works fine if I ssh in and run it. So what's the problem? Please advise as this is very important for me.
This is my root cron btw so I it's running as root.
I've tried to change ownership of the check script but so far no luck.
Help is greatly appreciated.
This is the script.
Code:
#!/bin/sh
isAlive=`/bin/pgrep httpd | wc -l`
if [ $isAlive -gt 400 ]
then
/usr/local/etc/rc.d/httpd restart
mail -s "Server Restart A" [email protected] < /log/check_mail.txt
fi
if [ $isAlive = 0 ]
then
/bin/sh /usr/local/etc/rc.d/httpd start
mail -s "Server Restart B" [email protected] < /log/check_mail.txt
fi
The script itself works as I get notification emails but for some reason the httpd start/restart doesn't work from cron. It works fine if I ssh in and run it. So what's the problem? Please advise as this is very important for me.
This is my root cron btw so I it's running as root.
I've tried to change ownership of the check script but so far no luck.
Help is greatly appreciated.