OPTIONS=""
PATH=$PATH:/usr/local/apache2/bin

function cleanup () {
    ######################################################################
    # erase apache2 log files and session files
    ######################################################################
    rm /usr/local/apache2/logs/error_log 2> /dev/null
    rm /usr/local/apache2/logs/access_log 2> /dev/null
    rm /tmp/sess* 2> /dev/null
    echo "apache2 error log file" > /usr/local/apache2/logs/error_log
    echo "apache2 access log file" > /usr/local/apache2/logs/access_log
    chmod 777 /usr/local/apache2/logs/* 2> /dev/null
    chown www-data:www-data /usr/local/apache2/logs/* 2> /dev/null
    rm /usr/local/apache2/htdocs/lock 2> /dev/null
}

case "$1" in
    start)
       echo -n "Starting apache2..."
       cleanup
       /usr/local/apache2/bin/apachectl start
       ;;
     restart)
       echo -n "Restarting apache2..."
       cleanup
       /usr/local/apache2/bin/apachectl restart
       ;;
     stop)
       echo -n "Stopping apache2..."
       /usr/local/apache2/bin/apachectl stop
       ;;
     *)
       echo "usage: start|restart|stop"
       ;;
esac
