Skip to content

Instantly share code, notes, and snippets.

@nickadam
Created February 1, 2016 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickadam/7f2b2c9d15964c03c8ee to your computer and use it in GitHub Desktop.
Save nickadam/7f2b2c9d15964c03c8ee to your computer and use it in GitHub Desktop.
Failback
#!/usr/bin/env bash
# Usage
if [ -z "$4" ] || [ "$1" == "--help" ]
then
echo "Please specify host (the system coming back), failover host (where the failover container"
echo "lives), the failover container, and the drbd resource"
echo " failover server-b server-a server-b-fo r1"
exit
fi
host="$1"
failover="$2"
container="$3"
resource="$4"
# unmount the resource on the contianer
if ! ssh root@"$container" /usr/local/sbin/failback
then
echo "Failover on $container failed"
exit 1
fi
# set the resource as secondary
if ! ssh root@"$failover" /sbin/drbdadm secondary $resource 2>/dev/null
then
echo "Set resource $resource to secondary failed on $failover"
exit 1
fi
# verify that resource is connected
if ! ssh root@"$host" /sbin/drbdadm cstate "$resource" 2>/dev/null | grep "^Connected$" > /dev/null
then
echo "Resource $resource is not connected on $host"
exit 1
fi
# verify that resource is uptodate
if ! ssh root@"$host" /sbin/drbdadm dstate "$resource" 2>/dev/null | grep "^UpToDate/UpToDate$" > /dev/null
then
echo "Resource $resource is not up to date"
exit 1
fi
# verify the resource is secondary everywhere
if ! ssh root@"$host" /sbin/drbdadm role "$resource" 2>/dev/null | grep "^Secondary/Secondary$" > /dev/null
then
echo "Resource $resource is not secondary everywhere"
exit 1
fi
# promote the resource on the host
if ! ssh "$host" /usr/local/sbin/drbd-autopromote "$resource" /mnt/btrfs
then
echo "Failed to promote $resource on $host"
exit 1
fi
# try to start/restart services on the container, reload haproxy config
ssh root@"$host" service haproxy start
ssh root@"$host" service haproxy reload
ssh root@"$host" service keepalived restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment