#!/bin/ksh93
#  ALTRAN_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  Copyright (C) Altran ACT S.A.S. 2017,2020,2021.  All rights reserved.
#
#  ALTRAN_PROLOG_END_TAG
#
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# 61haes_r721 src/43haes/usr/sbin/cluster/events/site_up.sh 1.12.1.1 
#  
# Licensed Materials - Property of IBM 
#  
# Restricted Materials of IBM 
#  
# COPYRIGHT International Business Machines Corp. 2000,2016 
# 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/events/site_up.sh, 726, 2147A_aha726, Feb 05 2021 09:50 PM

#########################################################################
#                                                                       #
#       Name:           site_up                                         #
#                                                                       #
#  Description:  This script is called when the first node		#
#                in a site joins the cluster.                           #
#                The script checks the id of the node,                  #
#                then calls one of the two sub-event script             #
#                accordingly.                                           #
#                                                                       #
#       Called by:      cluster manager                                 #
#                                                                       #
#       Calls to:       site_up_local, site_up_remote                   # 
#                                                                       #
#       Arguments:      sitename                                        #
#                       mode (forced, manual)                           #
#                                                                       #
#       Returns:        0       success                                 #
#                       1       failure                                 #
#                       2       bad argument                            #
#                                                                       #
#########################################################################

PROGNAME=${0##*/}
export PATH="$(/usr/es/sbin/cluster/utilities/cl_get_path all)"
if [[ $VERBOSE_LOGGING == high ]]
then
    set -x
    version='%I%'
fi


LOCAL_NODE=$(get_local_nodename)
set -a
eval $(cllsparam -n $LOCAL_NODE)
set +a

SITENAME=$1
typeset START_MODE=""
if (( $# > 1 )) && [[ $2 == "forced" ]]
then
    START_MODE="forced"
fi


typeset -i STATUS=0

#
# Call replicated resource site-up methods if they are defined
#
        
if [[ $START_MODE != "forced" ]]
then
    METHODS=$(cl_rrmethods2call site_initialization)

    for method in $METHODS
    do
        if [[ -x $method ]]
        then
            if ! $method $*
            then
                STATUS=1
            fi
        fi
    done
fi

set -u

if [[ "$SITENAME" == "$LOCALSITENAME" ]] 
then
    clcallev site_up_local $SITENAME $START_MODE
    (( STATUS += $? ))
else
    clcallev site_up_remote $SITENAME $START_MODE
    (( STATUS += $? ))
fi

exit $STATUS
