#!/bin/bash # configure shutdown priority here # nfs-client and nfs-export are special cases # it is assumed that nfs-client1 will run on nodeid1 and nfs-client2 on nodeid2 shutdownpriority="GENPKG5 GENPKG4 GENPKG3 GENPKG2 GENPKG1" # determine this node data thisnodeid="$(cman_tool status |grep "Node ID:" | awk '{print $3}')" thisnodename="$(cman_tool status |grep "Node name:" | awk '{print $3}')" # cache clustat output cluout="$(clustat)" # look for the other node data othernodename="$(cman_tool nodes -F id,name | grep -v "$thisnodeid "| awk '{print $2}')" # it is not enough to know if the node is running via cman, # we need to know if rgmanager is running or not and that's # what really matters to us if echo "$cluout" | grep $othernodename |grep -v "service:" | grep -q "RG-"; then othernodestatus="on" else othernodestatus="off" fi # workaround some shell expansion issues if [ "$thisnodeid" = "1" ]; then nfsclient=nfs-client1 else nfsclient=nfs-client2 fi if [ "$othernodestatus" = "on" ]; then # shutdown by priority but do not touch nfs-client. it has to # be the last to go, or it will be restarted on nfs-export relocation for i in $shutdownpriority nfs-export; do # for safety, we can only relocate services that in started state if echo "$cluout" | grep $i | grep $thisnodename | grep -q started; then clusvcadm -r $i -m $othernodename fi done # if both nodes are up, don't stop nfs-client, let rgmanager do that # this covers a corner case in service handling that central_processing # introduces by re-evaluting all service statuses each time a service # starts/stop. ## clusvcadm -s $nfsclient else # If the other node is not running rgmanager, we can safely # shutdown everything in order. # In this case nfs-client must be stopped before nfs-export # since nfs-export is going away forever. for i in $shutdownpriority $nfsclient nfs-export; do if echo "$cluout" | grep $i | grep -q started; then echo Stopping $i running on node $thisnodeid clusvcadm -s $i fi done fi