#!/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

RETVAL=0

start() {
	echo -n "Starting httpd: "
	daemon httpd
	RETVAL=$?
	echo
	# Wait for pid file to appear - it can take some time
	[ -f /var/run/httpd.pid ] || sleep 2
	[ -f /var/run/httpd.pid ] || sleep 2
	[ -f /var/run/httpd.pid ] || sleep 2
	[ -f /var/run/httpd.pid ] || sleep 2
	[ -f /var/run/httpd.pid ] || RETVAL=1
	return $RETVAL
}
stop() {
	echo -n "Shutting down http: "
	killproc httpd
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f /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=$?
	sleep 5
	if [ $(status httpd | egrep -c '(dead|stopped)' ) == 1 ]; then
	    /etc/rc.d/init.d/httpd-e-smith start
	fi
	echo
	;;
  graceful)
  	echo -n "Gracefully reloading httpd: "
	killproc httpd -USR1
	RETVAL=$?
	sleep 5
	if [ $(status httpd | egrep -c '(dead|stopped)' ) == 1 ]; then
	    /etc/rc.d/init.d/httpd-e-smith start
	fi
	echo
	;;
  *)
	echo "Usage: $0 {start|stop|restart|reload|graceful|status}"
	exit 1
esac

exit $RETVAL
