Created
February 6, 2014 07:28
-
-
Save nicolasochem/8839715 to your computer and use it in GitHub Desktop.
gluster failover test
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 | |
set +x | |
calculate() | |
{ | |
echo "\rSIGINT caught" | |
for i in {1..3} | |
do | |
was_failover=1 | |
old_timestamp="" | |
TIMESTAMPS=~/mounts/$i/$i/* | |
for timestamp in $TIMESTAMPS | |
do | |
timestamp=$(basename $timestamp) | |
if [[ "$old_timestamp" != "" ]] | |
then | |
time_diff=$(($timestamp - $old_timestamp)) | |
if [[ $time_diff -ne 1 ]] | |
then | |
echo "We've got a failover time of $time_diff in case $i" | |
was_failover=0 | |
fi | |
fi | |
old_timestamp=$timestamp | |
done | |
if [ $was_failover -ne 0 ] | |
then | |
echo "No downtime detected in case $i" | |
fi | |
done | |
cleanup | |
} | |
cleanup() | |
{ | |
rm -rf mounts/*/*/* | |
rm -rf mounts/*/* | |
umount mounts/* | |
rm -rf mounts | |
} | |
control_c() | |
# run if user hits control-c | |
{ | |
calculate | |
exit $? | |
} | |
cleanup | |
echo "Mounting..." | |
mkdir -p mounts/{1..3} | |
mount -t nfs annex:/puppet mounts/1 | |
mount -t glusterfs annex:/puppet mounts/2 | |
mount -t glusterfs -o backupvolfile-server=annex2 annex1:/puppet mounts/3 | |
mkdir -p mounts/1/{1..3} | |
echo "Mounts ok. Now bring down one of the annexes, wait 60 sec, then hit CTRL+C" | |
# trap keyboard interrupt (control-c) | |
trap control_c SIGINT | |
# set current date in epoch | |
while true | |
do | |
epoch=$(date +"%s") | |
if timeout 1 touch mounts/1/1/$epoch; then | |
echo "mount 1 is up" | |
fi | |
if timeout 1 touch mounts/2/2/$epoch; then | |
echo "mount 2 is up" | |
fi | |
if timeout 1 touch mounts/3/3/$epoch; then | |
echo "mount 3 is up" | |
fi | |
echo "Testing mounts..." | |
sleep 0.5 | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment