#!/bin/sh 
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r720 src/43haes/usr/sbin/cluster/haws/sbin/subsys/tds/stopTDS.sh 1.7 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2004,2015 
# 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 
# @(#)36	1.7 src/43haes/usr/sbin/cluster/haws/sbin/subsys/tds/stopTDS.sh, hacmp.assist, 61haes_r720, 1539B_hacmp720 9/11/15 11:37:12
#
###############################################################################
#
# This is a wrapper script for stopping TDS
#
###############################################################################

TDS_INSTALL_DIR=""
TDS_VG=""
TDS_DB_DIR=""
TDS_DB_VG=""

TDS_ADMIN=""
TDS_PASSWORD=""
TDS_PORT=""
TDS_DB_USER=""

###############################################################################
# Function: init
###############################################################################
#
# Initialize this script
###############################################################################
init() {
    # The standard directory for the HAWS software is in
    # /usr/es/sbin/cluster/haws. But this can be changed by setting the
    # environment string HAWS_HOME. 
    if [[ -z $HAWS_HOME ]]; then
        HAWS_HOME=/usr/es/sbin/cluster/haws
    fi

    # Source function library. This is standard for all scripts
    clhaws_functions=$HAWS_HOME/sbin/clhaws_functions
    if [[ ! -f  "$clhaws_functions" ]]; then
        echo "The file '$clhaws_functions' is missing! Unable to continue. Bye"
        exit 1
    fi
    . $clhaws_functions

    # We now call into the generic initialization routine. This will
    # complete the initialization process
    generic_init

    # once the above clhaws_functions complete, we have all our variables and 
    # functions defined. We can now safely log messages and begin processing.
    logmsg HAWS_TRACE "$MSG_BEGIN" "Begin\n"

}

###############################################################################
# Function: stop_tds
###############################################################################
#
# Stop TDS
###############################################################################
stop_tds() {
    set -x

    logmsg HAWS_TRACE $MSG_TDS_WEB_STOP "Stopping TDS...\n"
    $TDS_STOP_WEB_SERVER

    logmsg HAWS_TRACE $MSG_TDS_STOP "Stopping TDS...\n"
    $TDS_STOP_SERVER

    logmsg HAWS_TRACE $MSG_TDS_DB_STOP "Stopping TDS...\n"
    /usr/bin/su - $TDS_DB_USER -c "db2 force application all"
    /usr/bin/su - $TDS_DB_USER -c "db2stop"
    /usr/bin/su - $TDS_DB_USER -c "db2 terminate"
}


###############################################################################
# Function: read_config
###############################################################################
#
# Read our configuration file. Set up the command lines to stop TDS.
#
# 
###############################################################################
read_config() {
    cfgfile=$1
    logmsg HAWS_TRACE $MSG_READING_CONFIG "Reading configuration file: %s\n" $cfgfile
    . $cfgfile

    TDS_STOP_SERVER="$TDS_INSTALL_DIR/bin/ibmdirctl -D cn=$TDS_ADMIN -w $TDS_PASSWORD -p $TDS_PORT stop"
    TDS_STOP_WEB_SERVER="$WAS_INSTALL_DIR/bin/stopServer.sh $WAS_SERVER_NAME"
}

#
###############################################################################
#
# SCRIPT EXECUTION SECTION
#
###############################################################################
# This section of the script is used to call into the various predefined
# functions composed of the common code, and the script-specific functions.
#
# The intent of this section is to provide a high-level view of how this
# script operates.
###############################################################################
init
read_config $*
stop_tds
exit $HAWS_EXIT_SUCCESS
