How to , and other stuff about linux, photo, php … A linux, photography blog. To remember some linux situation, and fix them quickly.

February 9, 2012

EBS hangs in “attaching” mode

Filed under: Linux — Tags: , , , , , — admin @ 11:30 am

Well with the script bellow automatic script for backup up redis on a amazon ebs
I saw that was a problem.
From time to time the ebs hang with “attaching”
And the mount command die in D state. And the load on that server grow.
Well, we have modify the script to wait for the volume to be actually “attached” .

This is a improvement version of the script.


#!/bin/bash
date
instance=i-xxxxx
volume=vol-xxxx
iplocalhost=10.00.00.111

export EC2_HOME=/path/ec2-1.4.4.2
export JAVA_HOME=/usr/lib/jvm/jre
export CLASSPATH=${EC2_HOME}/lib
export EC2_PRIVATE_KEY=/root/path/pk.pem
export EC2_CERT=/root/path/cert.pem
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/aws/bin:/root/bin

if [ ! -d /mnt/backup ]; then
mkdir /mnt/backup
fi

if [ ! -f /tmp/redis1 ]; then
echo "Cron Started"
touch /tmp/redis1
else
echo "Cron already running"
exit 0
fi
atached=1
while [ $atached -eq 1 ];do
echo "">/root/status.txt
/opt/aws/bin/ec2-describe-volumes -K /root/path/pk.pem -C /root/path/cert.pem > /root/status.txt
if grep -q "available" "/root/status.txt" ; then
echo "Volume is available."
echo "Attaching Volume"
/opt/aws/bin/ec2-attach-volume -K /root/path/pk.pem -C /root/path/cert.pem $volume -i $instance -d /dev/sdh
atached=0
else
echo "Volume is already attached on other instance. Sleeping for 60 seconds"
sleep 60
fi
done
avaiable=1
COUNTER=1
while [ $avaiable -eq 1 ];do
/opt/aws/bin/ec2-describe-volumes -K /root/path/pk.pem -C /root/path/cert.pem $volume > /root/status.txt
if grep -q "attached" "/root/status.txt" ; then
echo "Volume is attached."
avaiable=0
echo "Mounting Volume"
mount /dev/sdh /mnt/backup
sleep 10
if [ -f /mnt/backup/montat ]; then
rsync -vrplogDtH /var/lib/redis/ /mnt/backup/redis
fi
else
echo "Volume is attaching. Sleeping for 60 seconds"
sleep 60
fi
if [ $COUNTER -eq 5 ]; then
echo "Quiting ater 5 minutes"
break
fi
let COUNTER+=1
done
umount -lf /mnt/backup
sleep 5
/opt/aws/bin/ec2-detach-volume -f -K /root/path/pk.pem -C /root/path/cert.pem $volume -i $instance -d /dev/sdh
sleep 5
rm -rf /tmp/redis1
exit;

1 Comment »

  1. Voսs faîtes toujoսrs des articles intéressants

    Comment by pipe hardcore — March 15, 2014 @ 2:31 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress