Skip to content

Commit

Permalink
Added m3.2xlarge EC2 instance type to swapfile setup
Browse files Browse the repository at this point in the history
  • Loading branch information
migurski committed Jan 22, 2015
1 parent 1035350 commit 468d6dd
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions ec2/swap.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
#!/bin/bash -e

function setup_swap() {
device=$1
size=$2

# fallocate works with ext4
umount /mnt
mkfs.ext4 $device
mount $device /mnt

# quickly allocate a large swapfile
fallocate -l $size /mnt/swapfile
chown root:root /mnt/swapfile
chmod 600 /mnt/swapfile

mkswap /mnt/swapfile
swapon /mnt/swapfile
}

IFS=$'\n'
for line in `cat /proc/mounts`; do
mount=`echo $line | cut -d' ' -f 2`
Expand All @@ -8,17 +26,13 @@ for line in `cat /proc/mounts`; do
fi
done

instance_type=`curl -s http://169.254.169.254/latest/meta-data/instance-type`
if [ -n $device ]; then
instance_type=`curl -s http://169.254.169.254/latest/meta-data/instance-type`

if [ -n $device -a $instance_type = 'm3.xlarge' ]; then
umount /mnt
mkfs.ext4 $device
mount $device /mnt
if [ $instance_type = 'm3.xlarge' ]; then
setup_swap $device 36G

fallocate -l 36G /mnt/swapfile
chown root:root /mnt/swapfile
chmod 600 /mnt/swapfile

mkswap /mnt/swapfile
swapon /mnt/swapfile
elif [ $instance_type = 'm3.2xlarge' ]; then
setup_swap $device 72G
fi
fi

0 comments on commit 468d6dd

Please sign in to comment.