httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc Slemko <ma...@znep.com>
Subject ndc-type script for manipulating httpd
Date Sun, 10 Aug 1997 00:49:59 GMT
(yes, the basic design for this was stolen from ndc... would probably have
to rewrite for copyright issues it to include it)

Below is the start of a basic script to control httpd.  It can be fleshed
out a good bit, needs to be abstracted a bit somehow to work with
different setups, and the status option needs to be implemented
differently (not that it can be implemented very cleanly...), but it is
just a start. 

I find it amazingly useful.  Anyone think we should include something like
it?

Oh, and the hardest thing is thinking of a good name for it.  <g>


#!/bin/sh

USAGE='echo "usage: $0 (status|restart|start|stop)"; exit 1'

PIDFILE=/usr/local/etc/httpd/logs/httpd.pid
HTTPD=/home/marcs/archive/apache/apache/src/httpd

if [ -f $PIDFILE ]
then
	PID=`cat $PIDFILE`
	PS=`ps $PID | tail -1 | grep $PID`
	RUNNING=1
	[ `echo $PS | wc -w` -ne 0 ] || {
		PS="httpd (pid $PID?) not running"
		RUNNING=0
	}
else
	PS="httpd (no pid file) not running"
	RUNNING=0
fi

for ARG
do
	case $ARG in
	start|stop|restart)
		;;
	*)
		[ $RUNNING -eq 0 ] && {
			echo $PS
			exit 1
		}
	esac

	case $ARG in
	start)
		[ $RUNNING -eq 1 ] && {
			echo "$0: start: httpd (pid $PID) already running"
			continue
		}
		$HTTPD && echo httpd server started
		;;
	stop)
		[ $RUNNING -eq 0 ] && {
			echo "$0: stop: httpd not running"
			continue
		}
		kill $PID && {
			echo httpd stopped
		}
		;;
	restart)
		[ $RUNNING -eq 1 ] && {
			kill -HUP $PID 
			# XXX check to see it doesn't die trying to restart
		}
		[ $RUNNING -eq 0 ] && {
			echo "$0: restart: httpd not running, starting"
			$HTTPD && echo httpd server started
		}
		;;
	status)
		[ $RUNNING -eq 0 ] && {
			echo "$0: status: httpd not running"
			continue
		}
		lynx -dump http://localhost/server-status
		;;
	*)	eval "$USAGE";;
	esac
done
test -z "$ARG" && eval "$USAGE"
exit 0


Mime
View raw message