#!/bin/sh

##
# Apache HTTP Server
##

. /etc/rc.common

StartService ()
{
    if [ "${WEBSERVER:=-NO-}" = "-YES-" ]; then
        ConsoleMessage "Starting Apache web server"
        if [ ! -e /etc/httpd/httpd.conf ] ; then
                cp -p /etc/httpd/httpd.conf.default /etc/httpd/httpd.conf
        fi
        apachectl start
        if [ "${WEBPERFCACHESERVER:=-NO-}" = "-YES-" ]; then
            if [ -x /usr/sbin/webperfcachectl ]; then
                ConsoleMessage "Starting web performance cache server"
                /usr/sbin/webperfcachectl start
            fi
        fi
    fi
}

StopService ()
{
    if [ -x /usr/sbin/webperfcachectl ]; then
        ConsoleMessage "Stopping web performance cache server"
        /usr/sbin/webperfcachectl stop
    fi
    ConsoleMessage "Stopping Apache web server"
    apachectl stop 
}

RestartService ()
{
    if [ "${WEBSERVER:=-NO-}" = "-YES-" ]; then
        ConsoleMessage "Restarting Apache web server"
        apachectl restart
        if [ "${WEBPERFCACHESERVER:=-NO-}" = "-YES-" ]; then
            if [ -x /usr/sbin/webperfcachectl ]; then
                ConsoleMessage "Restarting web performance cache server"
                /usr/sbin/webperfcachectl restart
            fi
        fi
    else
        StopService
    fi
}

RunService "$1"
