#!/bin/bash
#
# Startup script for the Apache Web Server
#
# chkconfig: - 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

# Source additional OPTIONS if we have them.
if [ -f /etc/sysconfig/apache ] ; then
	. /etc/sysconfig/apache
fi

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

# Change the major functions into functions.
moduleargs() {
	moduledir=/usr/lib64/apache
	moduleargs=`
	/usr/bin/find ${moduledir} -type f -perm -0100 -name "*.so" | awk '{\
		gsub(".*/","");\
		gsub("^mod_","");\
		gsub("^lib","");\
		gsub("\.so$","");\
		print "-DHAVE_" toupper($0)}'`
	echo ${moduleargs}
}
start() {
	echo -n $"Starting $prog: "
	daemon $httpd `moduleargs` $OPTIONS
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && touch /var/lock/subsys/httpd
	return $RETVAL
}
stop() {
	echo -n $"Stopping $prog: "
	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 $prog: "
	killproc $httpd -HUP
	RETVAL=$?
	echo
	;;
  condrestart)
	if [ -f /var/run/httpd.pid ] ; then
		stop
		start
	fi
	;;
  graceful)
	if [ -f /var/run/httpd.pid ] ; then
		killproc $httpd -USR1
	fi
	;;
  configtest)
	$httpd -t
	RETVAL=$?
	;;
  *)
	echo $"Usage: $prog {start|stop|restart|reload|condrestart|graceful|configtest|status}"
	exit 1
esac

exit $RETVAL
