Created
June 28, 2015 13:27
-
-
Save holly/0b3c96d3795957bfb1f5 to your computer and use it in GitHub Desktop.
keepalived+drbd sample
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
#!/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 |
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
#!/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 |
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
#!/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 |
Hello Holly,
Would you share with us and configuration example of keepalived using your scripts?
Regards,
Thiago
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Holly,
thanks for sharing the code. Could you give an example where should I store the scripts?
Cheers,
Marcel