#!/bin/ksh93
#  ALTRAN_PROLOG_BEGIN_TAG                                                    
#  This is an automatically generated prolog.                                  
#                                                                              
#  Copyright (C) Altran ACT S.A.S. 2019,2020,2021.  All rights reserved.  
#                                                                              
#  ALTRAN_PROLOG_END_TAG                                                      
#                                                                              
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r714 src/43haes/usr/sbin/cluster/sa/tsmadmin/sbin/cl_tsmadminstop.sh 1.2 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2010 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG
# @(#)  7d4c34b 43haes/usr/sbin/cluster/sa/tsmadmin/sbin/cl_tsmadminstop.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM
###############################################################################################
#
# NAME:
#       cl_tsmadminstop
#
# PURPOSE:
#       stop script of Smart Assist for TSM admin center
#
# ARGUMENTS:
#       	-a smart assist application name
#
# RETURNS
#  0 on success
#  1 on Failure
#
#################################################################################################

[[ "$VERBOSE_LOGGING" == "high" ]] && set -x
. /usr/es/sbin/cluster/sa/tsmadmin/sbin/cl_tsmadminGlobals
KLIB_HACMPLOG_ENTRY=$KLIB_TSM_ADMIN_HACMPLOG_ENTRY

while getopts a: opt
do
        case $opt in

                a) # admin application name, which will be highly available
                        app_name=$OPTARG
                        ;;

        esac
done

user=$(clodmget -q "name=TSM_AC_USER and application_id=$app_name" -f value -n HACMPsa_metadata)
set +x
pass=$(clodmget -q "name=TSM_AC_PASSWORD and application_id=$app_name" -f value -n HACMPsa_metadata | /usr/es/sbin/cluster/cspoc/cldecodearg)
set -x

if [[ -z $TSM_ADMIN_VERSION ]]
then
    ps -eo 'pid,args' | grep -vw grep |grep tsmServer > /dev/null 2>&1
    if [[ $? == 0 && -d $TSM_ADMIN_PROFILE_SCRIPTS ]]
    then
        KLIB_SA_logmsg INFO 2 32 tsmadminsa.cat "stoping the TSM Admin center\n"
        $TSM_ADMIN_PROFILE_SCRIPTS/stopServer.sh tsmServer -username $user -password $pass -nowait -quiet >> $LOG_FILE 2>&1
        exit $?
    fi
else
    ps -eo 'pid,args' | grep -vw grep | grep $TSM_ADMIN_INST_DIR/ui/Liberty > /dev/null 2>&1
    if [[ $? == 0 && -d $TSM_ADMIN_PROFILE_SCRIPTS ]]
    then
        KLIB_SA_logmsg INFO 2 32 tsmadminsa.cat "stoping the TSM Admin center\n"
        $TSM_ADMIN_PROFILE_SCRIPTS/stopserver.sh >> $LOG_FILE 2>&1 
        exit $?
    fi
fi
exit 0
