Skip to content

Instantly share code, notes, and snippets.

@teknogeek0
Created September 24, 2013 20:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teknogeek0/6690813 to your computer and use it in GitHub Desktop.
Save teknogeek0/6690813 to your computer and use it in GitHub Desktop.
ebsraider
#!/bin/bash
# made by Chris Munns
host_info=`ec2-describe-instances | grep $HOSTNAME`
host_id=`echo $host_info | awk '{print $2}'`
host_zone=`echo $host_info | awk '{print $11}'`
SCHEDULER=deadline
MDADMCOM=/sbin/mdadm
volNum=$1
volSize=$2
raidLvl=$3
raidDev=$4
devName=$5
mountP=$6
echo "On host $host_id in AZ $host_zone"
echo "Creating $volNum volumes of size $volSize GB for a RAID $raidLvl"
echo "which will be mounted /dev/$devName at $mountP"
## make the ebs volumes
for (( x=1; x<=volNum; x++))
do
ec2-create-volume -s $volSize -z $host_zone
done > /tmp/volsCreated.txt
## attach those ebs volumes to this instance
(i=0;
for vol in $(awk '{print $2}' /tmp/volsCreated.txt); do
i=$(( i + 1 ));
ec2-attach-volume $vol -i $host_id -d /dev/$devName${i};
## lets set the scheduler as well
echo $SCHEDULER > /sys/block/$devName${i}/queue/scheduler
done)
rm /tmp/volsCreated.txt
## sleep a bit so we wait for device intialization
sleep 30
## raid dem disks son
$MDADMCOM --create --level $raidLvl --chunk 256 --raid-devices $volNum -L $mountP /dev/$raidDev /dev/$devName*
### may not need this at all, commenting out until i see it break something
## make sure our array is initialized and active before moving on
#while [ -z "`cat /proc/mdstat | grep md1 | grep active`" ]
#do
# ## wait 10 more seconds
# sleep 10
# echo "Waiting for device initialization..."
#done
## create the mdadm.conf so that our array persists
mkdir -p /etc/mdadm
## take the results of scan and put it in the conf
$MDADMCOM --examine --scan --config=mdadm.conf >> /etc/mdadm/mdadm.conf
## lets format us a volume
/sbin/mkfs.xfs /dev/$raidDev
## mount up
mount -o noatime,nobarrier,nodiratime,logbufs=8 /dev/$raidDev $mountP
## persist in fstab
echo "LABEL=$mountP $mountP xfs noatime,nobarrier,nodiratime,logbufs=8 0 0" >> /etc/fstab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment