Skip to content

Instantly share code, notes, and snippets.

@nibalizer
Created August 31, 2012 09:01
Show Gist options
  • Select an option

  • Save nibalizer/3550531 to your computer and use it in GitHub Desktop.

Select an option

Save nibalizer/3550531 to your computer and use it in GitHub Desktop.
Script to restore drbd after a premature shutdown on a ganeti node
#!/bin/bash
#Don't run random scripts from the internet
exit
#this is for when you've broken an ganeti node, its still onish, but drbd has stopped communicating
failed_node=$1
affected_nodes=`gnt-instance list -o name,snodes | grep $failed_node | cut -d " " -f 1 `
#drbdsetup /dev/drbd22 net 10.208.8.23:11176 10.208.8.21:11176 C -A discard-zero-changes -B consensus
port=13337 #be sure to make sure iptables isn't just blocking the drbd port range
for name in $affected_nodes
do
#echo $name
inst_info=`gnt-instance info $name `
primary_drbd=`echo "$inst_info" | grep drbd |grep primary | awk '{print $3}'`
secondary_drbd=`echo "$inst_info" | grep drbd | grep secondary | awk '{print $3}'`
primary_node=`echo "$inst_info" | grep 'primary:' | awk '{print $3}' | tr -d ',' | head -n 1`
secondary_node=`echo "$inst_info" | grep 'secondaries:' | awk '{print $3}' | tr -d ',' `
#echo "$inst_info"
#echo $primary_drbd
#echo $secondary_drbd
#echo $primary_node
#echo $secondary_node
#exit
pri_base=`echo $primary_node | cut -d "." -f 1`
sec_base=`echo $secondary_node | cut -d "." -f 1`
pri_ip=`host $pri_base-iscsi | awk '{print $4}'`
sec_ip=`host $sec_base-iscsi | awk '{print $4}'`
let port+=1
#echo $pri_ip
#echo $sec_ip
#My use here is to > the output into a file, make that executable and run it, since hitting gnt-instance is time consuming and you really wnat to peer at this for a while before you run it.
echo "#Mapping for $name:"
echo "#$primary_drbd on $primary_node points to $secondary_drbd on $secondary_node"
echo ssh $primary_node \" drbdsetup $primary_drbd disconnect \"
echo ssh $primary_node \" drbdsetup $primary_drbd net $pri_ip:$port $sec_ip:$port C -A discard-zero-changes -B consensus \"
echo ssh $secondary_node \" drbdsetup $secondary_drbd disconnect \"
echo ssh $secondary_node \" drbdsetup $secondary_drbd net $sec_ip:$port $pri_ip:$port C -A discard-zero-changes -B consensus \"
echo ssh $primary_node \" drbdsetup $primary_drbd invalidate-remote \"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment