#! /bin/sh
#
# apache	Start the apache HTTP server.
#

NAME=apache
PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/sbin/apache
SUEXEC=/usr/lib/apache/suexec
PIDFILE=/var/run/$NAME.pid
CONF=/etc/apache/httpd.conf
APACHECTL=/usr/sbin/apachectl 

trap "" 1
trap "" 15

test -f $DAEMON || exit 0
test -f $APACHECTL || exit 0

if egrep -q -i "^[[:space:]]*ServerType[[:space:]]+inet\>" $CONF
then
    exit 0
fi

case "$1" in
  start)
    echo -n "Starting web server: $NAME"
    if $APACHECTL start > /dev/null 2>&1
    then
	echo "."
    else
	echo "... failed."
    fi
    ;;

  stop)
    echo -n "Stopping web server: $NAME"
    $APACHECTL stop > /dev/null
    echo "."
    ;;

  reload)
    echo -n "Reloading $NAME configuration... "
    if $APACHECTL graceful > /dev/null 2>&1
    then
	echo " done."
    else
	echo " failed."
    fi
    ;;

  reload-modules)
    echo -n "Restarting $NAME daemon."
    $APACHECTL stop > /dev/null
    start-stop-daemon --stop --quiet --oknodo --pidfile $PIDFILE > /dev/null
    echo -n "."
    sleep 4
    echo -n "."
    test -u $SUEXEC && echo
    if $APACHECTL start > /dev/null 2>&1
    then
	echo " done."
    else
	echo " failed."
    fi
    ;;

  restart)
    $0 reload-modules
    ;;

  force-reload)
    $0 reload-modules
    ;;

  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|reload|reload-modules|force-reload|restart}"
    exit 1
    ;;
esac

exit 0

