#!/bin/ksh # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # # # Licensed Materials - Property of IBM # # (C) COPYRIGHT International Business Machines Corp. 1997,2019 # 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 # @(#)62 1.5 src/rsct/pgs/samples/sample_deactive_ksh.sh, gssamples, rsct_rady, rady2035a 5/20/02 18:49:37 #/*********************************************************************/ #/* # * Name: sample_deactive_ksh # * # * This module provides a simple sample deactivation program that can # * be executed as part of an "expel" protocol against a provider, # * or an "failure" protocol if the deactivate-on-failure is enabled. # * It will expect the input parameters described as part of the # * Expel Protocol and the Deactivate-On-Failure Handling description # * in the IBM RSCT Group Services Programming Guide and Reference manual. # */ #/*********************************************************************/ # #/*********************************************************************/ #/* # * Expected input conditions: # * - effective uid and gid set to that of the client process connected # * to the Group Services daemon, at the time it issued ha_gs_init(). # * - current directory matches that of the client process connected # * to the Group Services daemon, at the time it issued ha_gs_init(). # * - path and other environment variables set to those used by the # * Group Services daemon. # * # * Expected input parameters: # * targetPid -- client process pid containing the provider targeted by the expel. # * timeLimit -- number of seconds within which this program must complete. # * groupName -- name of the group to which the targeted provider is joined. # * expelFlag -- flag specified by the provider initiating the expel. # * or "providerdied" as the deactivate-on-failure handling. # * failedProviders -- comma(,)-delimited list of the failed providers' # * local instance numbers. This parameter will be presented # * only for deactivate-on-failure handling. # * # * Special conditions: # * targetPid == 0 -- the provider's process id already failed during the # * expel protocol, or the deactivate-on-failure handling # * is initiated. Take any other necessary actions. # * # * expelFlag == NULL -- no flag was specified. # * == "providerdied" -- the deactivate-on-failure handling # * is initiated. # * # * Output (exit code): # * 0 -- means this program is "successful". It is up to this program to # * define "successful". # * !0 -- means this program is "unsuccessful". It is up to this program to # * define "unsuccessful". # */ #/*********************************************************************/ # #/*********************************************************************/ #/* # * In the case of the expel protocol: # * It is assumed that part of the normal action of a deactivate "script" # * will be to "kill" the targeted provider's process, since if we are # * running an expel we assume that the process is hung, or otherwise # * misbehaving. # * # * For the deactivate-on-failure: # * It will wait until (timeLimit + 5) to exit. Exit with zero. # * # * However, this is optional. This program should perform whatever # * actions make sense for the group and its providers. # */ #/*********************************************************************/ # #/*********************************************************************/ #/* # * For this sample program, we will use the *expel flag* as a key to # * our behavior. # * # * Flag values: # * NULL -- (no flag) No action, simply exit with 0 exit code. # * "kill" -- kill given process id (unless it is zero), exit with the # * return code from the kill command. # * "kill N" -- kill given process id (unless it is zero), exit with the # * value given by the integer N. # * "killwait" -- kill given process id (unless it is zero), but wait # * to exit until (timeLimit + 5). Always exit with zero. # * "wait" -- do not try to kill given process id, wait until # * (timeLimit + 5) to exit. Always exit with zero. # * "wait N" -- do not try to kill given process id, wait until # * (timeLimit + 5) to exit. N should be an integer, use it # * as our exit code. # * "N" -- N should be an integer, exit immediately with N as our exit # * code. # * # * "providerdied" -- wait until (timeLimit + 5) to exit. Exit with zero. # * This indicates deactivate-on-failure. # * # */ #/*********************************************************************/ extraWait=5 # Used to wait "extra" amount of time. targetPid=$1 # First three paramaters always there. timeLimit=$2 groupName=$3 if ((4 <= $#)) then expelFlag=$4 else expelFlag="" fi # Check expel flag, and see what to do. if [[ -z ${expelFlag} ]] then exit 0 # Null flag, just exit with zero exit code. fi if [[ $expelFlag = "killwait" ]] # Try to kill target process, then wait. then if ((0 != targetPid)) then kill -9 $targetPid # Kill the target process. fi ((sleepTime=timeLimit + extraWait))# Wait as long as specified. sleep $sleepTime exit 0 fi # Kill the process? If so, we may have a specific exit code that we # should use, rather than the kill return code. if [[ $expelFlag = "kill" ]] then killRc=0 if ((0 != targetPid)) # Have a pid? then kill -9 $targetPid # Try to kill it. killRc=$? # Save return code. fi if [[ -z $5 ]] # Was a flag given for exit code? then exit $killRc # No, exit with kill return code. fi if ((0 == killRc)) # Good result from kill, use given code. then exit $5 else exit $killRc # Reflect results from kill. fi fi # No killing, but we need to wait for some amount of time before # exiting. If given, use specified value for exit code. if [[ $expelFlag = "wait" ]] then if [[ -z $5 ]] # Was a flag given for exit code? then ((sleepTime=timeLimit + extraWait))# Wait as long as specified. sleep $sleepTime exit 0 # No special flag. else ((sleepTime=timeLimit + extraWait))# Wait as long as specified. sleep $sleepTime exit $5 fi fi # In the case of the deactivate-on-failure: # No killing, but we need to wait for some amount of time before # exiting. If given, use specified value for exit code. if [[ $expelFlag = "providerdied" ]] then failedProviders=$5 # holds the list of failed providers ((sleepTime=timeLimit + extraWait))# Wait as long as specified. sleep $sleepTime exit 0 # No special flag. fi # Nothing else, simply exit with the given value. exit $expelFlag