This guide will show a way to have some application running of an EBS volume. For simplicity we assume a Debian distro, but the same concept can be extented to other distros. In short we'll install a full system into the EBS volume and we'll install and start the services on the EBS volume.
euca-create-volume -s 5 -z windeuca-attach-volume -i i-31AB05AF vol-5957061D -d /dev/sdcmk2efs /dev/sdb1mkdir /ebs
mount /dev/sdb1 /ebsapt-get install debootstrapdebootstrap squeeze /ebsmount proc /ebs/proc -t proc
mount sysfs /ebs/sys -t sysfs
mount -o bind /dev /ebs/devchroot /ebsapt-get install locales
dpkg-reconfigure localesapt-get install apache2euca-authorize -P tcp -p 80 -s 0.0.0.0/0 defaultNow that you have a service running in an EBS volume you may want to make the starting and stopping easier: in this case we can have a script similar to this
#!/bin/bash
if [ ! -e /ebs/start_ebs.sh ]; then
echo "EBS volume is not mounted!"
exit 1
fi
if [ "$1" = "stop" ]; then
umount /ebs/sys
umount /ebs/proc
umount /ebs/dev
chroot /ebs /etc/init.d/apache2 stop
umount -lf /ebs
else
mount -t proc proc /ebs/proc
mount -t sysfs sysfs /ebs/sys
mount -o bind /dev /ebs/dev
chroot /ebs /etc/init.d/apache2 start
fi
and the best place to keep it is the EBS volume itself: log in to the instance, then copy the above script into /ebs and name it start_ebs.sh.
We can now move the EBS volume (and our service) to another instance:
. /ebs/start_ebs.sh stopeuca-detach-volume vol-5957061Deuca-attach-volume -i i-42B207F7 -d /dev/sdc vol-5957061Dmkdir /ebs
mount /dev/sdb1 /ebs. /ebs/start_ebs.sh startNow your web site moved to the new instance.
Of course this tecnique works very well coupled with elastic IPs: in this manner you can guarantee that the IP address of you web server will always be the same, just remember to use euca-associate-address and euca-disaccociate-address to move the IP around.
As an added benefit you can take backups of your EBS volume (in this case a web site) very easily:
euca-create-snapshot vol-5957061D