Created
January 27, 2016 15:45
-
-
Save nickadam/cd6a74b8bcf228bbbe07 to your computer and use it in GitHub Desktop.
DRBD Autopromote
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 | |
if [ -z "$1" ] | |
then | |
echo "Please specify resource to promote." | |
echo " drbd-autopromote r0" | |
exit 1 | |
fi | |
resource="$1" | |
mountpoint="/mnt/btrfs" | |
# find the device for this resource | |
device=$(cat /etc/drbd.d/"$resource".res | grep "^\s\+device" | head -n 1 | awk '{print $2}' | sed 's/\;//g') | |
if [ -z "$device" ] | |
then | |
echo "Could not find drbd device for $resource" | |
fi | |
# continually check ideal conditions before mounting and starting docker | |
while true | |
do | |
if /bin/mount | grep "^$device " > /dev/null | |
then | |
sudo service docker start | |
exit 0 | |
fi | |
# verify that resource is connected | |
if ! /sbin/drbdadm cstate "$resource" 2>/dev/null | grep "^Connected$" > /dev/null | |
then | |
echo "$(/bin/date) Resource $resource is not connected" | |
sleep 5 | |
continue | |
fi | |
# verify that resource is uptodate | |
if ! /sbin/drbdadm dstate "$resource" 2>/dev/null | grep "^UpToDate/UpToDate$" > /dev/null | |
then | |
echo "$(/bin/date) Resource $resource is not up to date" | |
sleep 5 | |
continue | |
fi | |
# verify the resource is secondary everywhere | |
if ! /sbin/drbdadm role "$resource" 2>/dev/null | grep "^Secondary/Secondary$" > /dev/null | |
then | |
echo "$(/bin/date) Resource $resource is not secondary everywhere" | |
sleep 5 | |
continue | |
fi | |
# set the resource as primary | |
if ! /sbin/drbdadm primary $resource 2>/dev/null | |
then | |
echo "$(/bin/date) Set resource $resource to primary failed" | |
sleep 5 | |
continue | |
fi | |
# mount the device | |
if ! /bin/mount $device $mountpoint | |
then | |
echo "$(/bin/date) Mount $device to $mountpoint failed" | |
sleep 5 | |
continue | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment