#!/bin/sh
#############################################################################
# Copyright (C)2004-2005, Sun Microsystems Inc. All rights reserved.
# Use is subject to license terms.
#
# Name: get_service_status
# Description: Common status retrieving function for the client services

# pragma ident	"$Id: "
##############################################################################

################################################################################
#  Function of the get_service_status
#  1.  Look up the status entry for the service passed in and return its value.
#################################################################################
#
# control logging method
#
log=echo
#log="logger -pdaemon.err"

if [ $# -ne 1 ] ; then
    $log  "Usage : `basename $0` <service_name> " 
    exit 1
fi

### load the ENUM file ##
### Get the int values of the command and status here. ###
enum_file=/usr/lib/cc-cfw/framework/lib/status_enum
if [ -f $enum_file ] ; then
    . $enum_file
else
    $log status_enum interface not found. 
    exit 1
fi

## Check for a valid ccr installation ##
/usr/lib/cc-cfw/framework/lib/get_interface CHECK_CCR > /dev/null
if [ $? -ne 0 ] ; then
    $log "The CCR package installation could not be verified.  Exiting."
    exit 1
fi
cli="/usr/lib/cc-ccr/bin/ccr"

## Assign arguments passed in ##
service_name=$1


###  Check if the service specific properties file exist. If not create one and add the entries. ###

prop_file=/var/cc-ccr/$service_name.properties

if [ ! -f $prop_file ] ; then
    $log The property file $prop_file does not exist, service not properly registered.
    return 
fi

## The status key string in the ccr ##
service_status_key="cns.service.$service_name.status"

## Get the status using ccr cli ##
## Get the status using ccr client interface ##
status_str=`$cli -g $service_status_key` 
if  [ $? -ne 0 ] ; then
    status_str="$STATUS_NOT_FOUND"
fi

case $status_str in
$ENABLE_STATUS_STRING)
    echo $ENABLE_STATUS_VALUE
    ;;
$DISABLE_STATUS_STRING)
    echo $DISABLE_STATUS_VALUE
    ;;
$START_STATUS_STRING)
    echo $START_STATUS_VALUE
    ;;
$STOP_STATUS_STRING)
    echo $STOP_STATUS_VALUE
    ;;
*)
    echo $STATUS_NOT_FOUND
esac




