Skip to content

Instantly share code, notes, and snippets.

@hanynowsky
Forked from holly/check_drbd.sh
Created April 3, 2018 13:21
Show Gist options
  • Save hanynowsky/e9cfdf1482325aa3a421a0c508e219d0 to your computer and use it in GitHub Desktop.
Save hanynowsky/e9cfdf1482325aa3a421a0c508e219d0 to your computer and use it in GitHub Desktop.
keepalived+drbd sample
#!/bin/bash
EXIT_CODE=0
STATUS_FILE=/tmp/drbd.status
STATUS=$(sed -e 's/.* state:\(.*\)$/\1/' $STATUS_FILE)
if [ "${STATUS}" != "MASTER" ]; then
echo "current status is ${STATUS}. skip"
exit
fi
DRBD_ROLE_STATUS=$(/sbin/drbdadm role r0 | cut -d '/' -f1)
DRBD_DSTATE_STATUS=$(/sbin/drbdadm dstate r0 | cut -d '/' -f1)
DRBD_CSTATE_STATUS=$(/sbin/drbdadm cstate r0)
[ "${DRBD_ROLE_STATUS}" != "Primary" ] && EXIT_CODE=1
#[ "${DRBD_DSTATE_STATUS}" != "UpToDate" ] && EXIT_CODE=2
#[ "${DRBD_CSTATE_STATUS}" != "Connected" ] && EXIT_CODE=3
echo "$(date +'%Y/%m/%d %H:%M:%S') check_drbd role:${DRBD_ROLE_STATUS} dstate:${DRBD_DSTATE_STATUS} cstate:${DRBD_CSTATE_STATUS} exit:${EXIT_CODE}" >> /tmp/check_drbd.log
exit $EXIT_CODE
#!/bin/bash
TYPE=$1 # “MASTER or BACKUP
DEVICE=/dev/drbd0
MOUNT_DIR=/drbd
drbd_primary() {
drbdadm primary r0
mount | grep -q $DEVICE
[ $? = 1 ] && mount -t xfs $DEVICE $MOUNT_DIR
}
drbd_secondary() {
mount | grep -q $DEVICE
[ $? = 0 ] && umount $MOUNT_DIR
drbdadm secondary r0
}
case $TYPE in
"MASTER")
drbd_primary
exit 0
;;
"BACKUP")
drbd_secondary
exit 0
;;
*) echo "unknown state"
exit 1
;;
esac
#!/bin/bash
TYPE=$1 # “GROUP” or “INSTANCE”
NAME=$2 # name of group or instance
STATE=$3 # target state of transition (“MASTER”, “BACKUP”, “FAULT”)
echo "$(date +'%Y/%m/%d %H:%M:%S') type:${TYPE} name:${NAME} state:${STATE}" > /tmp/drbd.status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment