#!/bin/sh
#
# ident "$Id$ SMI"
# 
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
###########################################
# chkconfig header info for RH
#
# chkconfig: 5 99 35
# description: Sun Ray Web Administration
#
###########################################
# insserv header info for JDS/SuSE
### BEGIN INIT INFO
# Provides:			utwadmin
# Required-Start:		utsvc utds
# X-UnitedLinux-Should-Start:
# Required-Stop:
# X-UnitedLinux-Should-Stop:
# Default-Start:		5
# Default-Stop:			1 2 3 4
# Short-Description:
# Description:			Sun Ray Web Administration
### END INIT INFO

# This script should not be invoked manually. The script is
# meant to start/stop the webserver automatically during system 
# startup and shutdown. To start the webserver manually use the 
# /opt/SUNWut/lib/utwebadmin script.

PRODUCT_INSTALL_DIR="/opt/SUNWut"
CONFIG_FILE="${PRODUCT_INSTALL_DIR}/webadmin/conf/webadmin.conf"
WEBADMIN_CMD="${PRODUCT_INSTALL_DIR}/lib/utwebadmin"

case "$1" in
'start')
    # check if webserver is enabled to start at boot time
    # should have auto.start=yes entry in config file
    if [ -f ${CONFIG_FILE} ]; then
        GO=`grep '^auto.start=' ${CONFIG_FILE} | cut -f2 -d'='`
        if [ "${GO}" = "true" -o "${GO}" = "TRUE" -o "${GO}" = "True" ]; then
            ${WEBADMIN_CMD} start
        fi
    fi
    exit 0
    ;;

'stop')
    if [ "`${WEBADMIN_CMD} status -p`" = "running=yes" ]; then
        ${WEBADMIN_CMD} stop
    fi
    exit 0
    ;;

*)
    echo "Usage: $0 { start | stop }"
    exit 1
    ;;
esac
exit 0
