Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

How to Prepare an Instance Image for Dynamic Tasks

kyolee310 edited this page Mar 19, 2013 · 3 revisions

How to Prepare an Instance Image for Dynamic Tasks

When developing applications in the cloud, at the early stage, it is beneficial to start with a generic instance image that can be morphed into serving different tasks. The simple trick is to modify the script "rc.local" in a Linux instance image.
Please check out the link http://open.eucalyptus.com/wiki/modifying-prepackaged-image to learn how to modify the default instance image provided by Eucalyptus.

Background: user-data

If you are developing a cloud application, you would want the instance to perform some tasks immediately after boot-up without having to log in. In such case, you want to take advantage of the ‘user-data’ field, which can be specified using the ‘-d’ option:

euca-run-instances emi-9BD01749 -k mykey0 -n 1 -g group0 -t c1.medium -d “”

Then, the instance can retrieve the line “” by using the command:
curl http://169.254.169.254/latest/user-data

This allows you to communicate directly with the instance that you just created.

Preparing the Instance Image

The goal is to modify the script "rc.local" so that it reads arguments from the ‘user-data’ and triggers actions automatically after the boot-up.
When working on the video-processing prototype, I used the generic Ubuntu Karmic image, provided in the Eucalyptus website, as the base image. Please check out the link http://open.eucalyptus.com/wiki/modifying-prepackaged-image to learn how to prepare an instance image.

The below lines are added at the end of the ‘rc.local’ script:


cd /home/renderer
echo “RUNNING /home/renderer/whatami.pl”
/usr/bin/perl ./whatami.pl > ./whatami.out 2> ./whatami.err &

exit 0


It simply means, “Go to the directory /home/renderer, and run the script ‘whatami.pl’.”

Now, you must create a directory “/home/renderer” and include a script called “whatami.pl”.

The script “whatami.pl” is designed to do the followings:

  1. Read the user-data field using curl http://169.254.169.254/latest/user-data
  2. Scan the first two words in the user-data
  3. Retrieve “” and “”
  4. Download the script from the file server
  5. Run the script

The mechanism above allows a cloud-user to convert instances to perform different tasks with the same instance image.

For instance, when the cloud-user would trigger an instance to run as a collector, then the command goes:

euca-run-instances emi-9BD01749 -k mykey0 -n 1 -g group0 -t c1.medium -d “collector.pl 192.168.7.77 ”

When the instance comes up, it will download the script ‘collector.pl’ from the file server ‘192.168.7.77’ via wget and run the script immediately.
The script ‘collector.pl’ automatically installs necessary softwares, via apt-get, on the instance to serve it as a collector.

On the other hand, if the user wants to run another instance that serve as a processor, then the user can use the same image with the different script:

euca-run-instances emi-9BD01749 -k mykey0 -n 1 -g group0 -t c1.medium -d “processor.pl 192.168.7.77 ”

At the early stage of the development on the cloud, having a such image comes very handy since a developer does not need to prepare different images for different tasks. However, keep in mind that, for the production, this approach might not be desirable due to the amount time it takes to convert a generic image to the mission-specific instances.

Setting up the File Server

The scenario above works if there is a machine serves as a file server that is reachable by all instances in the cloud. In other words, when the instances come up, they must be able to retrieve scripts and other necessary files via the command 'wget'.

In the video-processing prototype, I set up the file server in a such way that all the files are all located in the same directory under “www/scriptserver”. This allows the cloud instances to download a needed file via:

wget http://$ssip/scriptserver/$filename

where '$ssip' is the IP of the file server and '$filename' is the name of the file the instance wants.

The steps taken to set up the file server include:

  1. Locate a machine that is reachable by the cloud instances
  2. Install and set up Apache server
  3. Create a directory "www/scriptserver"
  4. Upload all the necessary files in the directory "www/scriptserver"
  5. Verify that the files are downloadable via 'wget'
    ex. Given the File Server’s IP 192.168.7.77
    wget http://192.168.7.77/scriptserver/collector.pl