Jeroen van Grondelle

Flower

Archive for the ‘How to’ Category

Compensating 3 Tons of CO2

Having travelled a lot this autumn, I decided to compensate for all the CO2 emitted while flying to Sicily, Madrid and Lisbon. Having read a number of opinions on the effectiveness of the different compensation schemes, based on planting trees, or reducing emissions on the other side of the world and then compensating that here, I was happy to learn about co2market.eu.

The emission permits you purchase here are bought of the european emission trading system. Every permit bought means a ton of CO2 is taken of the european CO2 budget.

Maybe, there are things to be said about this system as well, but never the less: Permits NL-1-1-3008692396-1-1, NL-1-1-3008692397-1-1 and NL-1-1-3008692398-1-1 were taken of the market in my name and won’t be spent by anyone else ;-)

OSGi in the Cloud

Running an OSGi container in a public cloud service, such as GoGrid.com, is the ultimate proof of the Scale Invariance promised in our Beyond Software Architecture presentation. Reason enough for Marcel Offermans and myself to give it a try and deploy our software on EC2.

Our goal is to us a standard EC2 image and run Java and an OSGi framework on it, through the use of PAXRunner. We will install software bundles onto the instance later, by a provisioning mechanism.

Subscribing

Go through the standard subscription process at aws.amazon.com and create an EC2 account. When completed, do three things.
- Add SSH port 22 to the default security group;
- Create a Private/Public Keypair;
- Download your Private Key, as you’ll need it to connect to your images

Choosing an AMI

At this stage, we are using a standard Ubuntu 9.04 AMI, provided by alestic.com (AMI ID: ami-ccf615a5).

Launch an instance and connect to it using SSH:

local> ssh -i EC2.pem root@ec2-a-b-c-d.amazonaws.com

Enable multiverse repositories by editing /etc/apt/sources.list. Add these four lines at the end (for EC2′s US-EAST cloud).

deb http://us.ec2.archive.ubuntu.com/ubuntu/ jaunty main multiverse
deb-src http://us.ec2.archive.ubuntu.com/ubuntu/ jaunty main multiverse
deb http://us.ec2.archive.ubuntu.com/ubuntu/ jaunty-updates main multiverse
deb-src http://us.ec2.archive.ubuntu.com/ubuntu/ jaunty-updates main multiverse

Update the APT database:

ec2> sudo apt-get update

Install java

Install Sun’s Java 6 JDK using APT:

ec2> sudo apt-get install sun-java6-jdk

Run an OSGi Framework using Pax Runner

A great way of installing and running an OSGi framework is using PAX Runner. PAX Runner transparently downloads and runs for you all major OSGi implementations.

Download and unarchive PAX Runner.

ec2> curl http://repo1.maven.org/maven2/org/ops4j/pax/runner/pax-runner-assembly/1.3.0/pax-runner-assembly-1.3.0-jdk15.tar.gz > pax-runner-assembly-1.3.0-jdk15.tar.gz
ec2> tar xzf pax-runner-assembly-1.3.0-jdk15.tar.gz

Installing and starting an OSGi Framework can be done by running PAX Runners shell script. By adding the URL of a bundle as a parameter, this bundle will be downloaded and started.

ec2> ./pax-runner-1.3.0/bin/pax-run.sh http://www.vangrondelle.com/code/hellocloud_1.0.0.jar
__________                 __________                                 
\______   \_____  ___  ___ \______   \__ __  ____   ____   ___________
|     ___/\__  \ \  \/  /  |       _/  |  \/    \ /    \_/ __ \_  __ \
|    |     / __ \_>    <   |    |   \  |  /   |  \   |  \  ___/|  | \/
|____|    (____  /__/\_ \  |____|_  /____/|___|  /___|  /\___  >__|   
               \/      \/         \/           \/     \/     \/       
 
Pax Runner (1.3.0) from OPS4J - http://www.ops4j.org
----------------------------------------------------
 
 -> Using config [classpath:META-INF/runner.properties]
 -> Using only arguments from command line
 -> Scan bundles from [http://www.vangrondelle.com/code/hellocloud_1.0.0.jar]
 -> Scan bundles from [scan-bundle:http://www.vangrondelle.com/code/hellocloud_1.0.0.jar]
 -> Provision bundle [http://www.vangrondelle.com/code/hellocloud_1.0.0.jar, at default start level, bundle will be started, bundle will be loaded from the cache]
 -> Preparing framework [Felix 2.0.1]
 -> Downloading bundles...
 -> http://www.vangrondelle.com/code/hellocloud_1.0.0.jar : 1078 bytes @ [ 359kBps ]
 -> Using execution environment [J2SE-1.6]
 -> Runner has successfully finished his job!
 
 
Welcome to Felix
================
 
Hello Cloud!
->

As you see, Felix is installed by default. Different OSGi implementations can be run by adding the --platform equinox|knopflerfish flag. Even the version to be installed can be specified.

Turning all this into a bootstrap script

For easy launching, you could add all this into a bootstrap script that turns a default Ubuntu image into an OSGi server with a single command.

Turning the Java installation into a silent install requires some additional scripting.

You can now install and run a bundle using the following command.

ec2> curl www.vangrondelle.com/code/bootstrap.sh | sh

This script needs some enhancements: Multiverse repositories are added everytime its run for now. Script might detect EC2 Zone and add appropriate repositories.

You are currently browsing the archives for the How to category.