[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

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


Closed Thread
 
LinkBack Thread Tools
Old 08-04-2007, 02:27 PM   #1 (permalink)
Senior Member
 
Crusader's Avatar
 
Join Date: Aug 2003
Location: Canada
Posts: 1,293
1,264.40 NP$ (Donate)

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

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
__________________

Near Fantastica
| Matthew Good - Vancouver
>> Do you Frawlik? <<
Crusader is offline  
Old 08-04-2007, 02:45 PM   #2 (permalink)
cef
NamePros Regular
 
Join Date: May 2004
Location: NYC
Posts: 236
76.50 NP$ (Donate)

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.

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, 03:11 PM   #3 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

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, 03:12 PM   #4 (permalink)
Senior Member
 
Crusader's Avatar
 
Join Date: Aug 2003
Location: Canada
Posts: 1,293
1,264.40 NP$ (Donate)

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

edit: isn't this running on bash?
__________________

Near Fantastica
| Matthew Good - Vancouver
>> Do you Frawlik? <<
Crusader is offline  
Old 08-04-2007, 03:38 PM   #5 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

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, 03:43 PM   #6 (permalink)
NamePros Regular
 
Join Date: Aug 2006
Location: USA
Posts: 725
212.90 NP$ (Donate)

enlytend is a name known to allenlytend is a name known to allenlytend is a name known to allenlytend is a name known to allenlytend is a name known to allenlytend is a name known to all


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 03:59 PM.
enlytend is offline  
Old 08-05-2007, 11:11 PM   #7 (permalink)
Senior Member
 
Crusader's Avatar
 
Join Date: Aug 2003
Location: Canada
Posts: 1,293
1,264.40 NP$ (Donate)

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.

Note: file.html should contain
Code:
<html>OK</html>
__________________

Near Fantastica
| Matthew Good - Vancouver
>> Do you Frawlik? <<

Last edited by Crusader; 08-05-2007 at 11:15 PM. Reason: additional
Crusader is offline  
Old 08-06-2007, 02:09 AM   #8 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services

 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Quote:
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.

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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 10:38 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85