FiveRuns Blog

On Rails production performance and monitoring

Posts
15 comments

Automatic Rails at Slicehost

This article details the scripted configuration of a Slicehost VPS for serving production Rails applications. Working with the FiveRuns team, it’s been valuable to deploy and redeploy a pristine Rails server environment quickly. This allows testing, debugging and simulating customer environments.

There are some great tutorials covering the step by step configuration of Ruby and Rails and Passenger at Slicehost. The main difference of this article is the script is self contained and does not require any user input except the password of your target slice. We’ll take your environment from blank build to live, serving a sample “Hello World” application in about 90 seconds.

The default root credentials are required for the initial connection to a new Slicehost slice. The setup script will run during that connection. After it completes and for production uses, the credentials should be updated and administrative, non-root accounts added. I chose Ubuntu 8.04 and its excellent package management to keep the configuration steps concise and convenient. Why not run this script directly on the server vs. passing it via ssh? You can. Executing remotely persists the script for easy repointing later or to multiple slice targets. Also, you can deploy other Rails applications from your local repositories using your Capistrano scripts.

Ubuntu’s apt-get packages can be dated, so feel free to substitute a more current version of any of these. I did this for the rubygems install to avoid the index update process of version 0.9.4 The steps to compile a specific version of Ruby is available in a previous blog post by Oliver. The packages and libraries installed are:

Ruby 1.8.6
Rubygems 1.2
Rails 2.1.0
Sqlite3
MySQL 5.0.51a
Thin 0.8.2

That’s it! I’ll add automation of more complex Rails apps and other Linux distros soon. Let me know if you have any requests.

#    This script will remotely configure your Slicehost VPS with the necessary applications and libraries
#    to serve and monitor a production Ruby on Rails application.  A simple "Hello World" Rails
#    Application is installed and started to confirm the process.
#  
#    Versions installed are Ruby 1.8.6, Rubygems 1.2, Rails 2.1.0. Sqlite3, MySQL 5.0.51a, Thin 0.8.2

#    Make remote ssh connection   (substitue your target server's address)
#  
ssh root@fiveruns.slicehost.com '

#    Update Ubuntu package manager
#
apt-get update
apt-get upgrade -y

#    Install dependencies
#
apt-get -y install build-essential libssl-dev libreadline5-dev zlib1g-dev  
apt-get -y install libsqlite-dev libsqlite3-ruby libsqlite3-dev 
apt-get -y install mysql-server libmysqlclient15-dev mysql-client 

#    Install Ruby 
#
apt-get -y install ruby ruby1.8-dev irb ri rdoc libopenssl-ruby1.8 

#    Install rubygems v.1.2 from source.  apt-get installs
#    version 0.9.4 requiring a lengthy rubygems update
RUBYGEMS="rubygems-1.2.0"
wget http://rubyforge.org/frs/download.php/38646/$RUBYGEMS.tgz
tar xzf $RUBYGEMS.tgz
cd $RUBYGEMS
ruby setup.rb
cd ..
ln -s /usr/bin/gem1.8 /usr/bin/gem

#    Install gems
# 
gem install -v=2.1.0 rails --no-rdoc --no-ri  
gem install mysql  --no-rdoc --no-ri
gem install tzinfo mysql thin --no-rdoc --no-ri

#    Configure a simple Rails Application
#
mkdir /var/www/
cd /var/www
rails hello
cd hello
./script/generate controller welcome hello
echo "Hello World" > app/views/welcome/hello.html.erb

#    Download FiveRuns Manage  ** Installation and registration is run seperately **
#    If you are new to FiveRuns, sign up for a free trial:  https://manage.fiveruns.com/signup
#    After, you have created an account, just execute the installer that is downloaded here
#
cd /tmp
wget http://manage.fiveruns.com/system/downloads/client/manage-installer-linux-ubuntu-64bit-intel.sh

#    Install the Manage gem and echoe gem dependency
#
gem install fiveruns_manage --source http://gems.fiveruns.com
gem install echoe --no-ri --no-rdoc

#    Install, configure and start the Thin web server
#
thin install
/usr/sbin/update-rc.d -f thin defaults
thin -p 80 config -C /etc/thin/hello.yml -c /var/www/hello
/etc/init.d/thin start
'

Bookmark and Share
Continued Discussion

15 responses to this entry

Great article. Thanks for taking the time to make this so simple!

Thom Parkin Thom Parkin said:

on September 24, 2008 at 03:09 PM

Slick! I guess the only improvement would be to install Ruby 1.8.7 ;)

Rails 2.1.1 wouldn’t be bad, either :)

Stephen Celis Stephen Celis said:

on September 24, 2008 at 09:40 PM

I’m interested in knowing why you used Thin for your script when the FiveRuns monitoring doesn’t support it.

Josh Schairbaum Josh Schairbaum said:

on September 25, 2008 at 12:07 PM

Thanks for your comments guys. I’ve had offline suggestions for more current Ruby/Rails versions too, so I’ll include those next.

We do support Thin, but occasionally see a permission or other issue interfering with the FiveRuns client’s metric upload. We can resolve these with a bit of troubleshooting.

Mark Mark said:

on September 25, 2008 at 04:14 PM

Holy Crap! This is awesome!

Melvin Ram Melvin Ram said:

on October 01, 2008 at 08:05 PM

Brilliant!

Robert Robert said:

on October 02, 2008 at 12:17 PM

Why do you load the MySQL ingredients and then load a MySQL gem? What’s the gem for?

David David said:

on October 03, 2008 at 02:33 PM

Hi David. The gem is a faster MySQL driver written in C and recommended for production environments. There is a native Rails connector but it will warn you regarding the above.

Mark Mark said:

on October 06, 2008 at 03:28 PM

Mark, you mind throwing this script on gist.github.com so that people can fork / follow updates to it?

Trotter Cashion Trotter Cashion said:

on October 10, 2008 at 11:48 AM

Trotter, great idea. Github is a natural for extending something like this. It’s now published to: http://github.com/mmond/configuration-automation.

Feel free to pull, fork or contrib back to core. Some areas I’ve seen interest in is Rails Machine, local server and VM configs, RedHat/CentOS and automating the initial server lockdown and credentials of a vanilla server.

Mark Mark said:

on October 11, 2008 at 02:27 PM

To late! I just moved to slicehost I did it long hand :( thanks for taking the time though, very useful and taught me a few things. A shall be revisiting it.

primordial primordial said:

on October 14, 2008 at 10:48 AM

Your post was very inspiring!

My favourite Rails stack contains Apache/Passenger/Ruby Enterprise Edition so I made a version of the script that does the all installation and configuration. Check it out my blog post and the corresponding gist

Jørgen Orehøj Erichsen Jørgen Orehøj Erichsen said:

on October 17, 2008 at 02:22 PM

Very nice artice!

Mark Mark said:

on October 19, 2008 at 10:46 AM

Hi folks. The latest automation updates include Capistrano, nginx, Mongrel, MySQL configuration, Github integration and the Eldorado Rails Application. Check out the next blog post.

Mark Mark said:

on October 19, 2008 at 04:54 PM

fiveruns you guys rock. thanks for making new slice deploys so easy.

Jonathan Nelson Jonathan Nelson said:

on October 23, 2008 at 11:01 AM

Contribute

Continue the conversation and share your thoughts. A name is required. Your e-mail address will not be displayed on the site. Textile formatting may be used in your comments (but will not be rendered in the live comment preview).

→ Posted by You on November 20, 2008 at 06:46 PM

Flickr

FiveRuns tagged photos on Flickr.

  • Mike
  • FiveRuns at the SF Ruby User Group
  • FiveRuns at the SF Ruby User Group
  • Inspiration - FiveRuns
  • Bruce Williams Arrives
  • Rachel
  • FiveRuns at the SF Ruby User Group
  • FiveRuns at the SF Ruby User Group

See more FiveRuns tagged photos…

Previous Entries

Other Categories

Entries are also organized under the following general topic categories.