#!/bin/sh
#
# Startup script for the Apache Web Server
#
# chkconfig: 345 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#	       HTML files and CGI.
# processname: httpd
# pidfile: /var/run/httpd.pid
# config: /etc/httpd/conf/access.conf
# config: /etc/httpd/conf/httpd.conf
# config: /etc/httpd/conf/srm.conf

# Source function library.
. /etc/rc.d/init.d/functions

# Path to the httpd binary.
httpd=/usr/sbin/httpd
RETVAL=0

# Until glibc's locale support is working right again, work around it.
LANG=C

# Change the major functions into functions.
moduleargs() {
	moduledir=/usr/lib/apache
	moduleargs=
	for module in ${moduledir}/*.so ; do
		if [ -x ${module} ] ; then
			module=`echo ${module} | awk '{\
				gsub(".*/","");\
				gsub("^mod_","");\
				gsub("^lib","");\
				gsub("\.so$","");\
				print toupper($0)}'`
			moduleargs="${moduleargs} -D HAVE_$module"
		fi
	done
	echo ${moduleargs}
}
start() {
	echo -n "Starting httpd: "
	daemon ${httpd} `moduleargs`
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
	return $RETVAL
}
stop() {
	echo -n "Shutting down http: "
	killproc httpd
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f /var/lock/subsys/httpd /var/run/httpd.pid
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	status ${httpd}
	;;
  restart)
	stop
	start
	;;
  reload)
	echo -n "Reloading httpd: "
	killproc ${httpd} -HUP
	RETVAL=$?
	echo
	;;
  condrestart)
	if [ -f /var/run/httpd.pid ] ; then
		stop
		start
	fi
	;;
  *)
	echo "Usage: $0 {start|stop|restart|reload|condrestart|status}"
	exit 1
esac

exit $RETVAL
