Tyler Bird If you're into DevOps, have I got a blog for you... hint: it's this one.

Rails Rumble Server Screencasts

Rails Rumble is one of my favorite parts of the year. I probably geek out about setting up the servers more than anything so I setup this article to show how I like to setup my servers for the competition. Complete with screencasts… Enjoy!

Server Setup

By the end of this screencast you’ll have a server running on linode with MySQL, REE, Passenger and Nginx ready to receive your application.

I will provide code snippets here in the blog article so you can copy and paste them into your terminal.

Boot Linode Instance

The steps in the screencast outline what to do, there isn’t anything you need to copy and paste from this section.

Setup Deploy User

I’ll be using the convention of root#, deploy$ and local$ to make it clear where and what user the command needs to be run as and where.

root# adduser deploy
root# visudo

# in the visudo file add the deploy user
deploy ALL=(ALL) ALL

root# /etc/init.d/ssh reload

Local Configuration

# Setup a ssh hostname.
local$ nano ~/.ssh/config

Host rumblebox
User         deploy

# Authme function
local$ nano ~/.profile

function authme {
ssh $1 'cat >>.ssh/authorized_keys' <~/.ssh/id_dsa.pub

# source your profile
local$ . ~/.profile

# log in and create .ssh folder
local$ ssh rumblebox
deploy$ cd ~
deploy$ mkdir -p .ssh

# now you'll be able to send your ssh key
local$ authme rumblebox
local$ ssh rumblebox # and you'll be logged in without a password prompt.

# If you have a passphrase on your ssh key you can use this cool trick:
local$ ssh-agent sh -c 'ssh-add < /dev/null && bash'

Install Server Packages

# prepare ubuntu
deploy$ sudo apt-get install build-essential git-core zlib1g-dev libssl-dev libreadline5-dev
deploy$ sudo apt-get update
deploy$ sudo apt-get upgrade

# install mysql
deploy$ sudo apt-get install mysql-server-5.1 mysql-client-5.1 libmysqlclient-dev zlib1g-dev libmysql-ruby1.8

# start mysql server
deploy$ sudo /etc/init.d/mysql start

# Test your sign in, change to *your* password
deploy$ mysql -uroot -prumbleROCK!

# install REE
deploy$ cd /usr/local/src
deploy$ sudo wget http://rubyforge.org/frs/download.php/71096/ruby-enterprise-1.8.7-2010.02.tar.gz
deploy$ sudo tar -xzvf ruby-enterprise-1.8.7-2010.02.tar.gz
deploy$ cd ruby-enterprise-1.8.7-2010.02
deploy$ sudo ./installer

# NOTE: change prefix to /usr/local so we don't have to mess with the PATH environment variable

# install nginx
deploy$ sudo passenger-install-nginx-module

# NOTE: remember to change prefix to /usr/local again

# configure nginx
deploy$ sudo nano /usr/local/conf/nginx.conf

server {
listen 80;
server_name _;
root /home/deploy/youstack/current/public;
passenger_enabled on;

# start nginx
deploy$ sudo /usr/local/sbin/nginx

IMPORTANT! Before your first bundler install on production will work you need to change permissions on the ~/.gem folder to deploy user.

deploy$ cd ~
deploy$ sudo chown -R deploy:deploy .gem/

Deployment Setup

After these steps and the second screencast you’ll be deploying to your Rails Rumble server! Let’s get started.

Generate Your App & Repo

local$ rails new youstack
local$ cd youstack/

local$ git init
local$ touch tmp/.gitignore log/.gitignore vendor/.gitignore

# .gitignore

local$ git status
local$ git add .
local$ commit -a

# the 'git remote' command is an ex., you'll use the one for your team.
local$ git remote add origin git@github.com:filmprog/youstack.git
local$ git push origin master

Setup Github Deploy Key

# connect to the server and generate a key
local$ ssh rumblebox
deploy$ ssh-keygen -t rsa
deploy$ cat ~/.ssh/id_rsa.pub

# the git ls-remote command needs to be run before you can deploy
deploy$ git ls-remote git@github.com:filmprog/youstack.git

Configure Cap, Bundler & DB


local$ capify .
  1. Copy and paste the deploy.rb from the following gist:


  1. And replace the :application, :password, and :repository values.

  2. Also you’ll need to update the IP address for your server.


  1. Add MySQL in the production group. group :production do gem 'mysql', '2.8.1' end

  2. Move SQLite 3 to development/testing group.

  3. Run ‘bundle install’ locally.

    local$ bundle install


adapter: mysql
encoding: utf8
reconnect: false
database: youstack_production
pool: 5
username: root
password: rumbleROCK!
socket: /var/run/mysqld/mysqld.sock

Deploy Your App

# commit your changes and push them to github
local$ git status
local$ git commit -a -m "adding capistrano, bundler and database configuration"
local$ git push

# setup the folders and do your first deploy
local$ cap deploy:setup
local$ cap deploy:check
local$ cap deploy

# create your database on the server
cap> cd /home/deploy/youstack/current/; rake RAILS_ENV=production db:create