#!/bin/ksh93 # ALTRAN_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # Copyright (C) Altran ACT S.A.S. 2018,2020,2021. All rights reserved. # # ALTRAN_PROLOG_END_TAG # # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # 61haes_r720 src/43haes/lib/ksh93/hacmp/KLIB_HACMP_resume_app_monitoring.sh 1.4 # # Licensed Materials - Property of IBM # # COPYRIGHT International Business Machines Corp. 2011 # 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 # @(#) 6fdea0a 43haes/lib/ksh93/hacmp/KLIB_HACMP_resume_app_monitoring.sh, 726, 2147A_aha726, Jun 09 2021 09:12 PM #============================================================================ # # Name: KLIB_HACMP_resume_app_monitoring # # Description: This is the main, FPATH function that is invoked by clmgr # to resume application monitoring for a specific application # running within a specific resource group. # # Inputs: See the "devDoc()" function, below. # # Outputs: Informational messages are written to STDOUT, and any error # messages that might be needed are written to STDERR. # # Returns: Zero if no errors are detected. Otherwise, an appropriate # non-zero value is returned. Refer to the "RETURN" section # of the "devDoc()" function, above, for the standard return\ # code values/meanings for clmgr. # #============================================================================ function KLIB_HACMP_resume_app_monitoring { . $HALIBROOT/log_entry "$0()" "$CL" : version= @(#) 6fdea0a 43haes/lib/ksh93/hacmp/KLIB_HACMP_resume_app_monitoring.sh, 726, 2147A_aha726, Jun 09 2021 09:12 PM : INPUTS: $* typeset application=${1//\"/} typeset rg=${2//\"/} [[ $CLMGR_LOGGING == 'med' ]] && set +x # Only trace param values #=================================== : Declare and initialize variables #=================================== typeset -i rc=$RC_UNKNOWN typeset -i LIST_APPS=1 typeset -i BAD_RG=0 typeset -u APP_UC=$application [[ $CLMGR_TIMEOUT != +([[:digit:]]) ]] && CLMGR_TIMEOUT=60 (( $CLMGR_TIMEOUT < 10 )) && CLMGR_TIMEOUT=10 #===================== : Validate the input #===================== if [[ -z $application ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 100 "\nERROR: a name/label must be provided.\n\n" 1>&2 rc=$RC_MISSING_INPUT elif [[ $APP_UC != "ALL" ]]; then CL=$LINENO KLIB_HACMP_is_known_appserver "$application" >/dev/null 2>&1 if (( $? == RC_SUCCESS )); then LIST_APPS=0 else dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$application" 1>&2 rc=$RC_NOT_FOUND fi fi if [[ $APP_UC != "ALL" ]] && (( LIST_APPS )); then dspmsg -s $CLMGR_SET $CLMGR_MSGS 141 "Available Applications:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_appservers available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" fi if [[ $APP_UC != "ALL" ]]; then if [[ -z $rg ]]; then dspmsg -s $CLMGR_SET $CLMGR_MSGS 101 '\nERROR: this operation requires the "%1$s" attribute.\n\n' RESOURCE_GROUP 1>&2 rc=$RC_MISSING_INPUT BAD_RG=1 else CL=$LINENO KLIB_HACMP_is_known_rg "$rg" >/dev/null 2>&1 if (( $? != RC_SUCCESS )) then dspmsg -s $CLMGR_SET $CLMGR_MSGS 102 '\nERROR: "%1$s" does not appear to exist!\n\n' "$rg" 1>&2 rc=$RC_NOT_FOUND BAD_RG=1 fi fi if (( BAD_RG )) then dspmsg -s $CLMGR_SET $CLMGR_MSGS 154 "Available Resource Groups:\n\n" 1>&2 typeset available CL=$LINENO KLIB_HACMP_list_resourcegroups available for (( i=0; i<${#available[*]}; i++ )); do if [[ ${available[$i]} != *([[:space:]]) ]]; then print -u2 "\t${available[$i]}" fi done print -u2 "" fi fi # : Make sure the cluster is up and running # typeset CSTATE=$(CL=$LINENO KLIB_HACMP_get_cluster_state) if [[ $CSTATE != "STABLE" ]]; then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 1300 '\nERROR: The cluster is not online, so this operation cannot be performed.\n\n' 1>&2 rc=$RC_MISSING_DEPENDENCY fi #================================================================== : Only proceed with the operation if the result is still unknown, : which means no input errors have been encounter. #================================================================== if (( $rc == RC_UNKNOWN )); then #========================================================== : Create an array populated with all application/RG pairs #========================================================== typeset -i index=0 typeset -A rgattrs typeset arr= if [[ $APP_UC == "ALL" ]]; then for pair in $(clodmget -n -q "name=APPLICATIONS" -f value,group HACMPresource); do arr[$index]="$pair" (( index++ )) done else arr[$index]="$application:$rg" fi for (( index=0; index<${#arr[*]}; index++ )); do application=${arr[$index]%:*} rg=${arr[$index]#*:} # : Make sure resource group "$rg" is up and running # CL=$LINENO KLIB_HACMP_get_resourcegroup_state "$rg" rgattrs if [[ ${rgattrs[STATE]} != "ONLINE" ]] then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 1301 '\nERROR: Resource group "%1$s" is not online, so this operation cannot be performed.\n\n' "$rg" 1>&2 rc=$RC_MISSING_DEPENDENCY continue else # : Make sure that monitoring for application "$application" : is in a suspended state for resource group "$rg" # typeset -u MSTATE=$(LC_ALL=C clRGinfo -c -m $rg 2>/dev/null | grep -w "$application" | cut -d: -f5) if [[ $MSTATE != *SUSPENDED* && $MSTATE != *FAILED* ]] then dspmsg -s $CLMGR_SET $CLMGR_MSGS 1460 '\nERROR: Application monitoring is already active.Current state is "%1$s" for application "%2$s" in resource group "%3$s".\n\n' "$MSTATE" "$application" "$rg" >&2 rc=$RC_ERROR continue fi fi print "$0()[$LINENO]($SECONDS): cl_RMupdate resume_appmon \"$application\" \"$rg\"" >>$CLMGR_TMPLOG # Always log commands cl_RMupdate resume_appmon "$application" "$rg" >>$CLMGR_TMPLOG 2>$TMPDIR/cl_RMupdate.$$ rc=$? print "$0()[$LINENO]($SECONDS): cl_RMupdate resume_appmon RC: $rc" >>$CLMGR_TMPLOG # Always log command result # : Load all the known, translated error strings from cl_RMupdate. # These strings match those found in clRMupdate.sh. # typeset CL_RMUPDATE_ERRORS CL_RMUPDATE_ERRORS[0]=$(cl_echo 9665 "cl_RMupdate: Failed to resume monitor(s) for application $application.\n" cl_RMupdate $application 2>&1) CL_RMUPDATE_ERRORS[1]=$(cl_echo 5002 "ERROR: cl_RMupdate: Unable to update the Cluster Manager with parameters resume_appmon and [0-9]+! Manual intervention may be required!\n" cl_RMupdate resume_appmon '[0-9]+' 2>&1) # : Check the STDERR file for known error messages. This is done : because it is not possible to trust the return code from that : utility. We can only check for error strings in the output. # for (( i=0; i < ${#CL_RMUPDATE_ERRORS[*]}; i++ )) do if [[ -n ${CL_RMUPDATE_ERRORS[$i]} ]] then grep -q "${CL_RMUPDATE_ERRORS[$i]}" $TMPDIR/cl_RMupdate.$$ if (( $? == 0 )) then rc=$RC_ERROR # Display on STDERR grep "${CL_RMUPDATE_ERRORS[$i]}" $TMPDIR/cl_RMupdate.$$ 1>&2 fi fi done cat $TMPDIR/cl_RMupdate.$$ >>$CLMGR_TMPLOG rm -f $TMPDIR/cl_RMupdate.$$ # Remove the temporary data file if (( $rc != RC_SUCCESS )); then rc=$RC_ERROR break else # These changes don't happen instantly, so wait for the state to change cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 1307 'Beginning the process of resuming monitoring. Waiting up to %1$d seconds for the state change to take effect...\n' "$CLMGR_TIMEOUT" typeset -u MSTATE="" for (( TRY=0; TRY/dev/null | grep -w "$application" | cut -d: -f5) if [[ -n $MSTATE && $MSTATE != *SUSPENDED* ]] then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 1306 'Monitoring for application "%1$s", running in resource group "%2$s", has resumed successfully.\n' "$application" "$rg" break fi sleep 1 done if [[ -z $MSTATE || $MSTATE == *SUSPENDED* ]] then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 1304 'Warning: the state change has not completed in the allotted time (%1$d seconds).\n' "$CLMGR_TIMEOUT" 1>&2 rc=$RC_ERROR fi fi done fi #======================================================================= : If a user input error was detected, provide some helpful suggestions #======================================================================= if (( $rc == RC_MISSING_INPUT || $rc == RC_INCORRECT_INPUT )) && \ [[ $CLMGR_GUI == *([[:space:]]) ]] then cl_dspmsg -s $CLMGR_SET $CLMGR_MSGS 104 "For more information about available options and syntax, try\n\"$HAUTILS/clmgr %1$s\". As an\nalternative, if the PowerHA SystemMirror man pages have been installed, invoke\n\"$HAUTILS/clmgr -hv\" (or \"/usr/bin/man clmgr\"),\nsearching for \"%2$s\" in the displayed text.\n\n" \ "manage application resume -h" "APPLICATION:" "$CLMGR_PROGNAME" 1>&2 fi log_return_msg "$rc" "$0()" "$LINENO" return $? } # End of "KLIB_HACMP_resume_app_monitoring()" #============================================================================ # # Name: devDoc # # Description: This is a never-to-be-called, wrapper function that all the # clmgr FPATH functions implement in order to hide embedded # syntax from trace logging. This information is implemented # in POD format, and can be viewed in a number of ways using # POD tools. Some viewing suggestions for this function's POD- # formatted information are: # # perldoc # pod2text -c # pod2text -c --code # pod2html # # However, the more important use for this information is that # it is parsed by clmgr to display the syntax for this file's # operation. The information in the "SYNOPSIS" section is used # for this purpose. This feature was originally implemented # using the man page information. However, in a code review it # was pointed out that this approach had to be changed because # customers do not have to install the man pages! Therefore, a # built-in dependency on man page information would break the # automatic help feature of clmgr. So the SYNPOSIS section must # be used instead. # # IMPORTANT: As a result of this, it is imperative that the # information in this SYNOPSIS be kept in sync # with the man page information, which is owned # by the IDD team. # # Inputs: None. # # Outputs: None. # # Returns: n/a (not intended to be invoked) # #============================================================================ function devDoc { : <<'=cut' >/dev/null 2>&1 =head1 NAME KLIB_HACMP_resume_app_monitoring =head1 SYNOPSIS clmgr manage application resume \ RESOURCE_GROUP= CLMGR_TIMEOUT Optional. Externally set in the environment. Sets the upper limit to wait for the overall operation to complete. If this limit is reached, an error is displayed and no results are returned. =head1 DESCRIPTION Resumes application monitoring for the specified application. =head1 ARGUMENTS 1. application [REQUIRED] [string] The name of the application whose monitoring will be resumed. 2. rg [REQUIRED] [string] The resource group that manages the application. =head1 RETURN 0: no errors were detected; the operation appears to have been successful 1: a general error has occurred 2: a specified resource does not exist, or could not be found 3: some required input was missing 4: some detected input was incorrect in some way 5: a required dependency does not exist 6: a specified search failed to match any data =cut } # End of "devDoc()" #============================================================================== # The following, comment block attempts to enforce coding standards when this # file is edited via emacs or vim. This block _must_ appear at the very end # of the file, or the editor will not find it, and it will be ignored. #============================================================================== # Local Variables: # indent-tabs-mode: nil # tab-width: 4 # End: #============================================================================== # vim: tabstop=4 shiftwidth=4 expandtab #==============================================================================