-
-
Save wallace/272472 to your computer and use it in GitHub Desktop.
application
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 -xe | |
EBS_DEVICE='/dev/sdh' | |
INSTANCE_ID=$1 | |
AKI=${2:-'aki-d314f0ba'} | |
ARI=${3:-'ari-d014f0b9'} | |
ARCH=${4:-'x86_64'} | |
SIZE=${5:-20} | |
AZ=${6:-'us-east-1a'} | |
NAME=${7:-"rollbook app"} | |
DESCRIPTION=${8:-'rollbook application server image with swap file'} | |
VOL_ID=`ec2-create-volume --size $SIZE -z $AZ |cut -f2|grep vol` | |
echo $VOL_ID | |
#sample output => VOLUME vol-0500xxx 10 us-east-1d creating 2009-12-05T08:07:51+0000 | |
ec2-attach-volume $VOL_ID -i $INSTANCE_ID -d $EBS_DEVICE | |
#sample output => ATTACHMENT vol-0500fxxx i-c72f6aaf /dev/sdh attaching 2009-12-05T08:14:17+0000 | |
echo "run the server side script on $INSTANCE_ID, and click enter when done:" | |
read waiting | |
ec2-detach-volume $VOL_ID | |
#sample output => ATTACHMENT vol-0500fb6c i-c72f 6aaf /dev/sdh detaching 2009-12-05T08:14:17+0000 | |
SNAP=`ec2-create-snapshot $VOL_ID|cut -f2|grep snap` | |
echo $SNAP | |
#sample output => SNAPSHOT snap-415b3xxx vol-0500xxx pending 2009-12-05T09:04:27+0000 424024621003 10 Ubuntu 9.10 base 32bit server image | |
ec2-register --snapshot $SNAP --kernel $AKI --ramdisk $ARI --description="$DESCRIPTION" --name="$NAME" --architecture $ARCH --root-device-name /dev/sda1 | |
#sample output => IMAGE ami-5007exxx |
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 | |
# Run this script on the instance to be bundled | |
# tested with Canonical Ubuntu 9.10 base ami | |
EBS_DEVICE=${1:-'/dev/sdh'} | |
IMAGE_DIR=${2:-'/mnt/tmp'} | |
EBS_MOUNT_POINT=${3:-'/mnt/ebs'} | |
mkdir -p $EBS_MOUNT_POINT | |
mkfs.ext3 ${EBS_DEVICE} | |
mount ${EBS_DEVICE} $EBS_MOUNT_POINT | |
#make a local working copy | |
mkdir /mnt/tmp | |
rsync --stats -av --exclude /root/.bash_history --exclude /home/*/.bash_history --exclude /etc/ssh/ssh_host_* --exclude /etc/ssh/moduli --exclude /etc/udev/rules.d/*persistent-net.rules --exclude /var/lib/ec2/* --exclude=/mnt/* --exclude=/proc/* --exclude=/tmp/* / $IMAGE_DIR | |
#ensure that ami init scripts will be run | |
chmod u+x $IMAGE_DIR/etc/init.d/ec2-init-user-data | |
#clear out log files | |
cd $IMAGE_DIR/var/log | |
for i in `ls ./**/*`; do | |
echo $i && echo -n> $i | |
done | |
cd $IMAGE_DIR | |
tar -cSf - -C ./ . | tar xvf - -C $EBS_MOUNT_POINT | |
#NOTE, You could rsync / directly to EBS_MOUNT_POINT, but this tar trickery saves some space in the snapshot | |
umount $EBS_MOUNT_POINT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment