#!/bin/bash # ########################################################### # DRBD 0.8.2.1 -> linux-cluster super-simple fencing wrapper # # Copyright Red Hat, 2007 # # Licensed under the GNU General Public License version 2 # which is incorporated herein by reference: # # http://www.gnu.org/licenses/gpl-2.0.html # # At your option, you may choose to license this software # under any later version of the GNU General Public License. # # This software is distributed in the hopes that it will be # useful, but without warranty of any kind. # # Kills the other node in a 2-node cluster. Only works with # 2-node clusters (FIXME?) # # ########################################################### # # Author: Lon Hohberger # # Special thanks to fabioc on freenode # PATH="/bin:/sbin:/usr/bin:/usr/sbin" NODECOUNT=0 LOCAL_ID=$(cman_tool status 2>/dev/null | grep '^Node ID:' | awk '{print $3}') REMOTE_ID="" REMOTE="" if [ -z "$LOCAL_ID" ]; then echo "Could not determine local node ID!" exit 1 fi # Shoot the other guy. while read nid nodename; do if [ "$nid" = "0" ]; then continue fi ((NODECOUNT++)) if [ "$nid" != "$LOCAL_ID" ]; then REMOTE_ID=$nid REMOTE=$nodename fi done < <(cman_tool nodes 2>/dev/null | grep -v '^Node' | awk '{print $1,$6}') if [ $NODECOUNT -ne 2 ]; then echo "Only works with 2 node clusters" exit 1 fi if [ -z "$REMOTE_ID" ] || [ -z "$REMOTE" ]; then echo "Could not determine remote node" exit 1 fi echo "Local node ID: $LOCAL_ID" echo "Remote node ID: $REMOTE_ID" echo "Remote node: $REMOTE " # # This could be cleaner by calling cman_tool kill -n , but then we have # to poll/wait for fence status, and I don't feel like writing that right # now. Note that GFS *will* wait for this to occur, so if you're using GFS # on DRBD, you still don't get access. ;) # fence_node $REMOTE if [ $? -eq 0 ]; then # # Reference: # http://osdir.com/ml/linux.kernel.drbd.devel/2006-11/msg00005.html # # 7 = node got blown away. # exit 7 fi # # Fencing failed?! # exit 1