Created
April 18, 2009 21:48
-
-
Save jrun/97795 to your computer and use it in GitHub Desktop.
source: http://bit.ly/EsrqQ
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/sh | |
# | |
# /etc/init.d/mountec2vol | |
# | |
# chkconfig: 234 20 50 | |
# description: Assigns an EC2 EBS Volume to a device and mounts the device | |
# | |
# To add this as a service run: | |
# /sbin/chkconfig --add mountec2vol | |
# | |
# VARS | |
# | |
VOL="vol-XXXXXXXX" | |
DEV="/dev/sdh" | |
MOUNT_POINT="/mnt" | |
export JAVA_HOME=/usr/java/jdk | |
export EC2_PRIVATE_KEY=/root/.ec2/pk-blahdeblah.pem | |
export EC2_CERT=/root/.ec2/cert-blahdeblah.pem | |
export EC2_HOME=/root/bin/ec2-api | |
PATH=$PATH:$HOME/bin:$EC2_HOME/bin | |
MAX_TRIES=60 | |
# start/stop functions for OS | |
case "$1" in | |
start) | |
INSTANCE=`curl http://169.254.169.254/latest/meta-data/instance-id 2> /dev/null` | |
CTR=0 | |
/bin/echo "Mounting Elastic Block Store Volumes." | |
ec2-attach-volume $VOL -i $INSTANCE -d $DEV | |
while [ ! -e "$DEV" ]; do | |
/bin/sleep 1 | |
CTR=`expr $CTR + 1` | |
if [ $CTR -eq $MAX_TRIES ] | |
then | |
/bin/echo "WARNING: Cannot attach volume $VOL to $DEV -- Giving up after $MAX_TRIES attempts" | |
exit 1 | |
fi | |
done | |
if [ ! -d $MOUNT_POINT ]; then | |
mkdir $MOUNT_POINT | |
fi | |
/bin/mount $DEV $MOUNT_POINT | |
;; | |
stop) | |
/bin/echo "Unmounting Elastic Block Store Volumes." | |
/bin/umount $MOUNT_POINT | |
ec2-detach-volume $VOL | |
;; | |
restart) | |
stop | |
sleep 5 | |
start | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart}" | |
exit 1 | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment