Circuit Self-managed infrastructure, programmatic monitoring and orchestration

Prepare host images

We are going to describe here a sequence of steps that will result in creating a new Amazon Machine Image (AMI), preloaded with software needed for this tutorial.

Start a fresh EC2 instance with an Ubuntu Linux base image. The plan is to install the needed software in a few simple manual steps and then save the state of the machine into the resulting image.

Install a few generic tools

Begin by updating the packaging system and installing a few handy generic tools:

	# sudo apt-get update
	# sudo apt-get install vim curl git

Install the circuit

Installing the Go compiler:

	# sudo apt-get install golang

Next, we need to create a directory for building the circuit. This directory will serve as the GOPATH directory that points the Go compiler to a source tree.

	# mkdir -p $HOME/0/src
	# echo "declare -x GOPATH=$HOME/0" >> ~/.bash_profile
	# source ~/.bash_profile

Fetch and build the circuit, then place the circuit executable in the system path:

	# go get github.com/gocircuit/circuit/cmd/circuit
	# cp $GOPATH/bin/circuit /usr/local/bin

Make sure the installation succeeded by running circuit start, to start the circuit daemon, and then simply kill it with Control-C.

Finally, prepare a scratch directory which we will later use for the circuit daemon to write logging and other such information.

	# mkdir /var/circuit

Install MySQL server

Install MySQL using the default packaged distribution. The installation will prompt you for a root user password — feel free to use the empty string to simplify the tutorial:

	# sudo apt-get install mysql-server

As a side-effect, the installer will put MySQL in the boot sequence of this machine. We would like to disable that as we plan to manage (start/stop) the service through our circuit application. Thus, disable the automatic boot startup of MySQL using:

	# echo manual | sudo tee /etc/init/mysql.override

Install node.js and the tutorial node.js app

Last, we need to install Node.js as well as the example Node.js app that we have prepared for this tutorial, to serve as a RESTful HTTP API front-end for the key/value store, backed by MySQL.

Install Node.js with:

	# sudo apt-get install nodejs npm

The Node.js app for this tutorial is located in the circuit's source tree. We already have a local clone of the source tree (as a result of the go get command earlier). We are simply going to copy it out of the source tree and place it nearby for convenience:

	# cd $HOME
	# cp -R $GOPATH/src/github.com/gocircuit/circuit/tutorial/nodejs-using-mysql/nodejs-app .

And prepare the Node.js app for execution by fetching its Node.js package dependencies:

	# cd $HOME
	# cd nodejs-app
	# npm install

Save the image

We are done installing. It is best to now “stop” (rather than “terminate”) the Amazon host instance. Once the instance has stopped, use your Amazon EC2 console to save its current state to a new machine image.