NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page restart httpd on fail

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 08-04-2007, 03:27 PM THREAD STARTER               #1 (permalink)
Senior Member
 
Crusader's Avatar
Join Date: Aug 2003
Location: Canada
Posts: 1,257
Crusader is just really niceCrusader is just really niceCrusader is just really niceCrusader is just really nice
 



restart httpd on fail


I'm using this script (I think I got it off of WHT) to restart httpd whenever a file failed to download on my server.

Code:
#!/bin/bash

FILE=http://www.domain.tld/test.file

rm -f test.file
wget -q $FILE -O test.file

if [ ! -f test.file ]
then
       /etc/init.d/httpd restart
       echo 'ALERT - HTTPD restarted on:' `date` | mail -s "Alert: HTTPD Restarted" user@domain.tld
fi

exit $?
I have it on crontab
????: NamePros.com http://www.namepros.com/programming/357862-restart-httpd-on-fail.html

Code:
*/5 * * * * /bin/nfup > /dev/null 2>&1
but it didn't seem to restart httpd, I got no e-mail and our site was down for several hours.

Is there anything wrong with the script?

Thanks
Crusader is offline  
Old 08-04-2007, 03:45 PM   #2 (permalink)
cef
NamePros Regular
Join Date: May 2004
Location: NYC
Posts: 236
cef is a jewel in the roughcef is a jewel in the roughcef is a jewel in the rough
 


Animal Rescue
I'm guessing you don't have write permissions for test.file, wherever your script is trying to dump it. Add an absolute path to a location where you have write permissions.
????: NamePros.com http://www.namepros.com/showthread.php?t=357862

Code:
rm -f /path/you/can/write/to/test.file
wget -q $FILE -O /path/you/can/write/to/test.file

if [ ! -f /path/you/can/write/to/test.file ]
You might also need to set umask at the start of the script to make sure you can read/write the file as well, but try the above first.
cef is offline  
Old 08-04-2007, 04:11 PM   #3 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
It is also possible that the user running the script does not have permissions to restart the service (you could see what user is running the process by doing a whoami command within the script).

Out of interest why are you using a php script, why not just use a bash script?
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Peter is offline  
Old 08-04-2007, 04:12 PM THREAD STARTER               #4 (permalink)
Senior Member
 
Crusader's Avatar
Join Date: Aug 2003
Location: Canada
Posts: 1,257
Crusader is just really niceCrusader is just really niceCrusader is just really niceCrusader is just really nice
 



The cron was running as ROOT and i've seen the file show up before. Someone on WHT suggested I use this:

Code:
#!/bin/sh
FILE=http://www.domain.tld/test.file
wget -q $FILE

if [ ! -f test.file ]

then
/etc/init.d/httpd restart
echo 'ALERT - HTTPD restarted on:' `date` | mail -s "Alert: HTTPD Restarted" user@domain.tld
fi

rm -rf test.file*
Apparently there's something wrong with the -O
????: NamePros.com http://www.namepros.com/showthread.php?t=357862

edit: isn't this running on bash?
Crusader is offline  
Old 08-04-2007, 04:38 PM   #5 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,069
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
that looks like it will be a better opting than using a php script.
__________________
Manage your portfolio using my new Domain Portfolio Management script.
Securing Your Domain Name From Theft
Peter is offline  
Old 08-04-2007, 04:43 PM   #6 (permalink)
Forum Moderator
 
enlytend's Avatar
Join Date: Aug 2006
Location: USA
Posts: 2,036
enlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond reputeenlytend has a reputation beyond repute
 



Cancer Survivorship
If it's still not working, try sending the output to a file in some writeable directory (instead of /dev/null) so you can see any errors it spits out:

*/5 * * * * /bin/nfup > /tmp/somefilename 2>&1

If it's a cron issue, most cron problems are usually either paths, environments or permissions. Cron runs with a limited environment, not the user's standard login environment so things need to be spelled out in your script.

Once you get this running, I hope next thing on the agenda is to try to find out why httpd is crashing ? Sounds like you have much worse problems than getting this script to run!
Last edited by enlytend; 08-05-2007 at 04:59 PM.
enlytend is offline  
Old 08-06-2007, 12:11 AM THREAD STARTER               #7 (permalink)
Senior Member
 
Crusader's Avatar
Join Date: Aug 2003
Location: Canada
Posts: 1,257
Crusader is just really niceCrusader is just really niceCrusader is just really niceCrusader is just really nice
 



Talked it over on a few forums and came up with this:

Code:
#!/bin/bash
tmp_file="/home/user/test_file"
wget -t 1 -T8 -O $tmp_file http://www.domain.tld/file.html >> /dev/null 2>&1
test=`grep OK $tmp_file`
if [ "$test" == "" ]; then
        #echo "File download failed, assuming offline."
        /etc/init.d/httpd restart
        echo 'ALERT - HTTPD restarted on:' `date` | mail -s "Alert: HTTPD Restarted" you@domain.tld
elif [ "$test" == "<html>OK</html>" ]; then
        echo "HTTPD seems to be OK" >> /dev/null 2>&1
else
        #echo "Unknown error..."
        echo 'ALERT - HTTPD had an unkown error on:' `date` | mail -s "Alert: HTTPD Error" you@domain.tld
fi
rm -rf $tmp_file
Apparently WGET will download something even if it isn't there so you should check what's in the file first. I don't know if this'll work though but I'm hoping.
????: NamePros.com http://www.namepros.com/showthread.php?t=357862

Note: file.html should contain
Code:
<html>OK</html>
Last edited by Crusader; 08-06-2007 at 12:15 AM. Reason: additional
Crusader is offline  
Old 08-06-2007, 03:09 AM   #8 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Originally Posted by Crusader
Talked it over on a few forums and came up with this:

Code:
#!/bin/bash
tmp_file="/home/user/test_file"
wget -t 1 -T8 -O $tmp_file http://www.domain.tld/file.html >> /dev/null 2>&1
test=`grep OK $tmp_file`
if [ "$test" == "" ]; then
        #echo "File download failed, assuming offline."
        /etc/init.d/httpd restart
        echo 'ALERT - HTTPD restarted on:' `date` | mail -s "Alert: HTTPD Restarted" you@domain.tld
elif [ "$test" == "<html>OK</html>" ]; then
        echo "HTTPD seems to be OK" >> /dev/null 2>&1
else
        #echo "Unknown error..."
        echo 'ALERT - HTTPD had an unkown error on:' `date` | mail -s "Alert: HTTPD Error" you@domain.tld
fi
rm -rf $tmp_file
Apparently WGET will download something even if it isn't there so you should check what's in the file first. I don't know if this'll work though but I'm hoping.
????: NamePros.com http://www.namepros.com/showthread.php?t=357862

Note: file.html should contain
Code:
<html>OK</html>
http://www.rfxnetworks.com/sim.php
Eric is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 10:58 PM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger