Created
February 1, 2016 18:24
-
-
Save nickadam/7f2b2c9d15964c03c8ee to your computer and use it in GitHub Desktop.
Failback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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