Obliterate-peer.sh (DRBD fence handler): Difference between revisions

From Alteeve Wiki
Jump to navigation Jump to search
No edit summary
 
Line 3: Line 3:
This is the [[Red Hat]] <span class="code">obliterate</span> script used to let [[DRBD]] trigger a [[cman]] [[fenced]] call when a split brain is detected. This was originally found [http://people.redhat.com/lhh/obliterate-peer.sh here].
This is the [[Red Hat]] <span class="code">obliterate</span> script used to let [[DRBD]] trigger a [[cman]] [[fenced]] call when a split brain is detected. This was originally found [http://people.redhat.com/lhh/obliterate-peer.sh here].


Download the <span class="code">/sbin/[https://alteeve.com/files/an-cluster/sbin/obliterate-peer.sh obliterate-peer.sh]</span> script, ~2.1[[KiB]].
Download the <span class="code">/sbin/[https://alteeve.ca/files/an-cluster/sbin/obliterate-peer.sh obliterate-peer.sh]</span> script, ~2.1[[KiB]].


<source lang="bash">
<source lang="bash">

Latest revision as of 03:22, 5 May 2013

 AN!Wiki :: Obliterate-peer.sh (DRBD fence handler)

This is the Red Hat obliterate script used to let DRBD trigger a cman fenced call when a split brain is detected. This was originally found here.

Download the /sbin/obliterate-peer.sh script, ~2.1KiB.

#!/bin/bash
# ###########################################################
# DRBD 0.8.2.1 -> linux-cluster super-simple fencing wrapper
#
# Kills the other node in a 2-node cluster.  Only works with
# 2-node clusters (FIXME?)
#
# ###########################################################
#
# Author: Lon Hohberger <lhh[a]redhat.com> 
#
# Special thanks to fabioc on freenode
#
# http://sources.redhat.com/cluster/wiki/DRBD_Cookbook
# http://people.redhat.com/lhh/obliterate
#
# Nethesis - http://www.nethesis.it
# Federico Simoncelli <federico.simoncelli@nethesis.it>
# $Id: obliterate-peer.sh 709 2009-06-10 10:59:21Z federico $

PATH="/bin:/sbin:/usr/bin:/usr/sbin"

LOCAL_ID=$(cman_tool status | awk '/Node ID:/{print $3}')

if [ -z "$LOCAL_ID" ]; then 
	logger -t $0 "Could not determine local node ID!"
	exit 1
fi

DISK_UPTODATE=$(drbdadm get-gi $DRBD_RESOURCE | awk -F: '{print $6}')

if [ "$DISK_UPTODATE" != 1 ]; then
	logger -t $0 "Local node is not UpToDate!"
	exit 6
fi

NODECOUNT=0
while read NODE_ID NODE_NAME; do
	[ $NODE_ID = 0 ] && continue
	[ $NODE_ID != $LOCAL_ID ] && REMOTE=$NODE_NAME
	((NODECOUNT++))
done < <(cman_tool nodes | awk '!/^Node/{print $1,$NF}')

if [ $NODECOUNT -ne 2 ]; then
	logger -t $0 "Only works with 2 node clusters"
	exit 1
fi

if [ -z "$REMOTE" ]; then
	logger -t $0 "Could not determine remote node"
	exit 1
fi

logger -t $0 "Local node ID: $LOCAL_ID / Remote node: $REMOTE"

# Killing the remote node if it's still part of the cluster
cman_tool kill -n $REMOTE 2>&1 | logger -t $0

# Shoot the other guy.
for FENCE_ATTEMPT in $(seq 0 9); do 
	#
	# This could be cleaner by calling cman_tool kill -n <node>, 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

        sleep 3
done

#
# Fencing failed?!
#
exit 1

 

Any questions, feedback, advice, complaints or meanderings are welcome.
Alteeve's Niche! Enterprise Support:
Alteeve Support
Community Support
© Alteeve's Niche! Inc. 1997-2024   Anvil! "Intelligent Availability®" Platform
legal stuff: All info is provided "As-Is". Do not use anything here unless you are willing and able to take responsibility for your own actions.