#!/bin/ksh
###############################################################################
#
# Sun Cluster Sun MTP Data Service version 1.0
#
# Sun MTP Stop script for scmtp.
#
###############################################################################
EMP_SETUP=none
EMP_SRV_ID=none
EMP_DEBUG=OFF

typeset opt

while getopts 'S:I:T:D:' opt
do
  case "$opt" in
    S)
    # Setup path name
    EMP_SETUP=$OPTARG
    ;;
    I)
    # Data service identifier
    EMP_SRV_ID="$OPTARG"
    ;;
    D)
    # Debug option
    EMP_DEBUG=$OPTARG
    ;;
    T)
    # Shut down time out
    EMP_STOP_TIMEOUT=$OPTARG
    ;;
    *)
    kixlog "mtp_stop: warning option $OPTARG unknown"
    ;;
  esac
done

if [ "$EMP_SETUP" = "none" ]
then
    kixlog "mtp_stop: Error. Setup file has not been specified"
    exit 101
fi

. $EMP_SETUP

if [ "$EMP_DEBUG" = "ON" ]
then
  kixlog "mtp_stop: $0 started with \"$*\" parameters"
fi

if [ "$EMP_SRV_ID" = "none" ]
then
    kixlog "mtp_stop: Error. Data service identifier has not been specified"
    exit 102
fi

kixlog "Stopping MTP data service $EMP_SRV_ID `hostname`, timeout=$EMP_STOP_TIMEOUT"

kixhashut -t $EMP_STOP_TIMEOUT
ret_status=$?

kixlog "mtp_stop: kixhashut returns status=$ret_status, exit code=$ret_status"
exit $ret_status
