#!/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. 
# 
#


#kill all services on localhost
#!! be warned: this is a brutal script: nothing will survive after it is done...
#
#we dont need to unbind since we kill the registry as well...

. ${TOP}/bin/get_params.sh

${ECHO} "killing services on localhost"

${ADMIN_DIR}/abort/abort_svc.sh --svc_name=appsvr_${SHORT_HOSTNAME} --unbind=no

# if we have to kill rmi, flag it and kill it after killing all other services ( since
# these try to connect to rmi, and will fail if it is killed before)

foundrmiflag=0

for pid in `ls ${SVC_LOG_DIR}/*/svc.pid 2>/dev/null`; do
    SVC_DIR=`dirname $pid`
    SVC_NAME=`basename $SVC_DIR`

    if [ "$SVC_NAME" != "rmi_${SHORT_HOSTNAME}"  ]; then
        ${ADMIN_DIR}/abort/abort_svc.sh --svc_name=${SVC_NAME} --unbind=no
    else
        foundrmiflag=1
    fi
done

if [ "$foundrmiflag" -eq 1 ]; then
    ${ADMIN_DIR}/abort/abort_svc.sh --svc_name=rmi_${SHORT_HOSTNAME} --unbind=no
fi

case ${CCD_APPSVR} in
    websphere|websphere5|websphere6|websphereAE)
        if [ -n "${_CCD_APPSERVERNAMES}" ]; then
            n=1
            while [ -n "`${ECHO} ${_CCD_APPSERVERNAMES}|cut -f $n -d ,`" ];
            do
                $TOP/bin/go/abort/abort_appsvr.sh --svc_name=appsvr${n}_${SHORT_HOSTNAME} --appservername=`${ECHO} ${_CCD_APPSERVERNAMES}|cut -f $n -d ,`
                let n=$n+1
            done
        elif [ -z "${_CCD_APPSERVERS}" ]; then
            $TOP/bin/go/abort/abort_appsvr.sh
        elif [ ${_CCD_APPSERVERS} -gt 1 ]; then
            for ((n=1;n<=${_CCD_APPSERVERS};n++))
            do
                $TOP/bin/go/abort/abort_appsvr.sh --svc_name=appsvr${n}_${SHORT_HOSTNAME} --appservername=${WAS_APPSERVERNAME}${n}
            done
        else
            $TOP/bin/go/abort/abort_appsvr.sh
        fi
    ;;
esac
