#!/bin/ksh93
#  ALTRAN_PROLOG_BEGIN_TAG                                                    
#  This is an automatically generated prolog.                                  
#                                                                              
#  Copyright (C) Altran ACT S.A.S. 2017,2018,2019,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/events/resource_offline_dispatcher.sh 1.7 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2006,2013 
# 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 
# @(#)  9f023c6 43haes/usr/sbin/cluster/events/resource_offline_dispatcher.sh, 726, 2147A_aha726, Feb 19 2021 01:54 PM

#================================================
# The following, commented line enforces coding
# standards when this file is edited via vim.
#================================================
# vim:tabstop=4:shiftwidth=4:expandtab:smarttab
#================================================

#########################################################################
#
#   COMPONENT_NAME: CLMGR
#
#   FUNCTIONS: none
#
#########################################################################

#########################################################################
#                                                                       #
#       Name:           resource_offline_dispatcher                     #
#                                                                       #
#       Description:    This event script is called when a resource     #
#                       is to be brought offline                        #
#                                                                       #
#       Called by:      resource_offline                                #
#                                                                       #
#       Calls to:       node_down_local or                              #
#                       KLIB_HACMP_offline_resourcegroup                #
#                                                                       #
#       Arguments:      resource_group_name   [clean]                   #
#                                                                       #
#       Returns:        0       success                                 #
#                       1       failure                                 #
#                                                                       #
#########################################################################

function on_offrg_exit {
    [[ -f /var/hacmp/log/offrgd.$$ ]] && rm -f /var/hacmp/log/offrgd.$$
}
trap 'on_offrg_exit' INT TERM HUP EXIT


[[ "$VERBOSE_LOGGING" == "high" ]] && set -x
: version=@(#)  9f023c6 43haes/usr/sbin/cluster/events/resource_offline_dispatcher.sh, 726, 2147A_aha726, Feb 19 2021 01:54 PM
: INPUTS == $*

typeset rg=$1
typeset node=$2
typeset -l mode=$3
typeset primary=$4
typeset secondary=$5

#===================================
# Declare and initialize variables
#===================================
typeset -i STATUS=0

#=========================================
# Call KLIB if the resource_offline was
# *not* called with the argument "clean"
#=========================================
if [[ $mode != c* ]]; then
    CL=$LINENO . $HALIBROOT/func_include
    CL=$LINENO KLIB_HACMP_offline_resourcegroup "$rg" "$node" "$primary" "$secondary"
    STATUS=$?

#==========================================================
# If we are here, then a resource clean up was requested,
# just to cleanup the resources that belong to an offline
# resource group. Please refer to the NDS feature.
#==========================================================
else
    #====================================================
    # Export some variables that affect node_down_local
    #====================================================
    set -a
        PATH="$($(dirname ${0})/../utilities/cl_get_path all)"
        : RC=$?

        LOCALNODENAME=$(get_local_nodename)
        : RC=$?

        UPDATESTATD=0
        PLATFORM="__AIX__"

        eval $(cllsparam -n "$LOCALNODENAME")
        : RC=$?

        eval $(clsetenvres "$rg" node_down)
        : RC=$?

        FORCEDOWN_GROUPS="" 
        RESOURCE_GROUPS=""
        HOMELESS_GROUPS=""
        HOMELESS_FOLLOWER_GROUPS=""
        PRINCIPAL_ACTIONS="" 
        ASSOCIATE_ACTIONS="" 
        AUXILLIARY_ACTIONS=""

        GROUPNAME=$rg
        RESOURCES_CLEANUP="CLEANUP"
        PRINCIPAL_ACTION="RELEASE"
        AUXILLIARY_ACTION="NONE"
    set +a

    #=========================================================
    # Call "node_down_local" to bring the resources offline.
    # NOTE: the exported environment variables, above, serve
    #       as the input to "node_down_local".
    #=========================================================
    node_down_local 2>/var/hacmp/log/offrgd.$$
    STATUS=$?

    (( STATUS != 0 )) && cat /var/hacmp/log/offrgd.$$
    [[ -f /var/hacmp/log/offrgd.$$ ]] && rm -f /var/hacmp/log/offrgd.$$
fi

exit $STATUS