Customizing your Scalarium Cloud using Chef: The Scalarium Lifecycle System

Scalarium sports a couple of lifecycle events that can occur during the lifetime of an instance. Each event causes a
configuration to be sent down to the instance. This configuration is simply a big JSON file containing information about the cloud
the instance is running in, and information on which steps it needs to go through to update the instance's configuration
to reach a successful and working setup or to reflect the changes in the cloud.

The first one is "setup" and will be sent to the instance when it successfully booted. The Scalarium default is to
install a bunch of dependencies, and to set the machine up to reflect its role. For the Rails application server, that
includes installing Apache, Ruby Enterprise Edition, Passenger and Ruby on Rails.

The second event is "configure", and it's sent to all instances whenever the state of their cloud changes, e.g. an
instance was successfully added to the cloud, or another one was shut down. With this event we notify e.g. the load
balancer software HAProxy to update its configuration to reflect the changes, so that if an application server shut
down, it's removed from the available HAProxy backends.

The third one is "deploy" and is triggered whenever you deploy an application. For the Rails application server, the
default is to check out the source code and tell Passenger to reload the application.

While we run some of our own things on all these events, we allow you to fully customize your clouds by hooking into
them. Before we dive in, let's look at how we can use the different events to set up Redis. We can use the "setup"
event to download and install the Redis server. For the Redis server we don't need much else, once it's set up, it will
stay up and running.

As for the Rails application server, we'll use the "configure" and "deploy" events, which will both do the same in our
case, to write a configuration for the Rails application containing the data required to access the Redis server. For
convenience, we'll also add a "setup" task to install the Redis default library for Ruby on the instance.

Next step: Cooking with Chef

Or go back to the start