Monday, August 09, 2010

Apachectl: Use Wget instead of Lynx

A common error with apachectl is 'cannot find lynx'. This is a silly error because lynx is a text mode browser that is just used to retrieve the server-status page and grep out pertinent information.

Building Lynx just for use starting, stoppping, restarting, graceful, status, statusfull, etc. on Apache is silly. Most servers already have Curl or Wget. I prefer wget because it's simple and easy to use.

To use wget instead of lynx, modify your apachectl file as follows:

1. add a line near the top with:

# PIDFILE
PIDFILE='/home/username/local/apache/logs/httpd.pid'

2. About line 90-ish, you'll see status) - you should make it look like this:

configtest)
$HTTPD -t
ERROR=$?
;;
status)
# $LYNX $STATUSURL | awk ' /process$/ { print; exit } { print } '
/usr/bin/wget $STATUSURL -q -O - | egrep '(Current|Restart|uptime)' | sed 's/<[/]*dt>//g'
if [[ -f $PIDFILE ]] ; then
echo "PID: " `cat $PIDFILE`
else
echo "No PID file."
fi
;;
fullstatus)
$LYNX $STATUSURL
;;
*)


This uses wget to grab the status (uptime, restart time, etc.) instead of Lynx, which as I said should be discontinued as a dependency. As you can see, Wget solves the problem easily.

Note that the bottom section for fullstatus) is not changed; I didn't need the fullstatus, if you do, feel free to improve on this text.

Enjoy!
Post a Comment