#!/bin/bash
# Licensed Materials - Property of IBM
# 5724-I68
#
# (C) Copyright IBM Corp. 2000, 2006
#
# US Government Users Restricted Rights - Use, duplication, or
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp.

# 
# # Copyright (c) 2000, 2004 IBM Corp. - All Rights Reserved.
# # IBM makes no representations or warranties about the suitability of
# # this program, either express or implied, including but not limited to
# # the implied warranties of merchantability, fitness for a particular
# # purpose, or non-infringement. 
# 
#


. ${TOP}/bin/get_params.sh

SVC_NAME=${_CCD_SVC_NAME:=appsvr_${SHORT_HOSTNAME}}
. ${ADMIN_DIR}/init_svc_vars.sh

WAS_APPSERVERNAME=${_CCD_APPSERVERNAME:=${WAS_APPSERVERNAME}}

${ADMIN_DIR}/stop/stop_svc.sh --svc_name=${SVC_NAME}

case "${CCD_APPSVR}" in
    websphere)
        InitEtcDirForAppSvr websphere
        if [ -e ${WAS_HOME}/bin/stopServer.sh ]; then
            ${WAS_HOME}/bin/stopServer.sh -configFile ${SVC_ETC_DIR}/websphere/server-cfg.xml
        else
            echo "Warning!  \$CCD_APPSVR set to websphere, but couldn't find stopServer.sh!"
            echo "If you are using WebSphere Advanced Edition, please set \$CCD_APPSVR to \"websphereAE\""
        fi
        ;;
    websphereAE)
        InitEtcDirForAppSvr websphere
        ${WAS_HOME}/bin/wscp.sh -p ${TOP}/etc/default/websphere/wscp.properties -f ${ADMIN_DIR}/websphere/stop.tcl ${WAS_NODENAME} ${WAS_APPSERVERNAME}
        ;;
    websphere5)
        InitEtcDirForAppSvr websphere
        if [ -n "$WAS_SECURITY" ]; then
            ${ECHO}
            ${ECHO} "You have indicated that WAS security is enabled.  Please provide the"
            ${ECHO} "following authentication information:"
            ${ECHO} "WAS Username:"
            read -p "> " WAS_USERNAME
            ${ECHO} "WAS Password (will not echo):"
            read -p "> " -s WAS_PASSWORD
            ${ECHO}
            ${WAS_HOME}/bin/stopServer.sh ${WAS_APPSERVERNAME} -username $WAS_USERNAME -password $WAS_PASSWORD
        else
            ${WAS_HOME}/bin/stopServer.sh ${WAS_APPSERVERNAME}
        fi
        ;;
    websphere6)
        InitEtcDirForAppSvr websphere
        if [ -n "$WAS_SECURITY" ]; then
            ${ECHO}
            ${ECHO} "You have indicated that WAS security is enabled.  Please provide the"
            ${ECHO} "following authentication information:"
            ${ECHO} "WAS Username:"
            read -p "> " WAS_USERNAME
            ${ECHO} "WAS Password (will not echo):"
            read -p "> " -s WAS_PASSWORD
            ${ECHO}
            ${WAS_PROFILE_HOME}/bin/stopServer.sh ${WAS_APPSERVERNAME} -username $WAS_USERNAME -password $WAS_PASSWORD
        else
            ${WAS_PROFILE_HOME}/bin/stopServer.sh ${WAS_APPSERVERNAME}
        fi
        ;;
    *)
        ;;
esac
