« January 2008 | Main | March 2008 »

deprec2: Mongrel, nginx, Rails, mysql on Ubuntu 7.1

Feb 26 by Andre in Ruby on Rails »

Following up on my previous post on low-cost staging environments, I chose a host and set up my staging environment.

Note: these are the steps I took to make it work. They are probably not the optimal steps. Actually, I'll go one step further: I guarantee you these are not the optimal steps. But, I did get my staging environment up and running in less then three hours.

1) signed up for SilverRack.

Why? Dave from SilverRack offers $10 off if you're involved in a Ruby user group, which makes the total cost of a 256MB vps $10/mo. Hard to beat that from a pure cost perspective.

  • signup took two minutes including paying my first month on paypal
  • the VPS was provisioned about two minutes after that. I had originally chosen centos, but realized I needed Ubutu 7.1 for deprec 2 -- SilverRack has a simple web-based reinstall you can do yourself, and it took a minute. Note: the Rails stack on CENTOS (before I changed to Ubuntu) looked like it was Rails 1.2 based.

2) install new cap

(I hadn't upgraded to 2 yet)

sudo gem install capistrano -v2.1.0

3) install deprec 2 preview

... I had a hard time finding the gem; grab it from the wiki page like so: curl http://www.deprec.org/attachment/wiki/WikiStart/deprec-1.99.13.gem?format=raw > deprec-preview.gem

sudo gem install deprec-preview.gem

4) decided to create myself a little deprec play area, but I'm not sure it's necessary:

cd ~/projects mkdir deprec cd deprec mkdir config depify .

4.5) set up ssh keys

. . . I know deprec provides some tasks for this, but I just did it manually (copied my local ~/.ssh/id_rsa.pub) into my new vps's ~/.ssh/

5) let's setup a rails stack!

Used an IP because my dns hasn't resolved yet. If your dns has resovled ... good for you!

export HOSTS=xxx.xxx.xxx.xxx 

# here comes the big one . . .
cap deprec:rails:install_rails_stack

ok, it almost made it through ... ran for a few minutes and failed on sqlite3. Specifically, it failed here:

executing `deprec:rails:install'
executing `deprec:rails:install_deps'
executing "sudo -p 'sudo password: ' \n      
sh -c \"DEBCONF_TERSE='yes' DEBIAN_PRIORITY='critical' 
DEBIAN_FRONTEND=noninteractive apt-get -qyu --force-yes  
install libmysqlclient15-dev sqlite3 libsqlite3-ruby libsqlite3-dev \""

.. with the error:

Package sqlite3 is not available, but is referred to by another package. This may mean that the package is missing, has been obsoleted, or is only available from another source. E: Package sqlite3 has no installation candidate

After ssh'ing on the server, fooling around with apt-get myself, googling sqlite3/ubuntu, etc, still no love. So I went ghetto on this one:

sudo vi /opt/local/lib/ruby/gems/1.8/gems/deprec-1.99.13/lib/deprec/recipes/rails.rb

.. and removed the two sqlite related libs from the recipe (sqlite3 libsqlite3-ruby), at around line 77. Bottom line is that all my apps use mysql, so I knew I wouldn't miss sqlite

6) NOW let's setup a rails stack!

Since deprec's installrailsstack had made it almost all the way though, I checked out the recipe to see what's left. Turned out it's just one task:

cap deprec:rails:install

That's it. At this point my server has Rails2, a bunch of gems including mongrel, nginx, mysql, and probably a whole bunch of other stuff I don't know about yet.

7) so . . . how do you deploy to staging?

I didn't want to figure out the "right" way to configure Capistano for a staging environment right now. Plus, my project already has a (non-depified) deploy.rb, which I don't want to mess with right now.

In the interest of expediency, I just checked out a separate copy of my app and:

rm config/deploy.rb
depify .
vi config/deploy.rb

... add set :user, 'root', updated :application, :repository, :domain, and the three roles (:app, :web, :db)

cap setup 

cap deprec:deploy

... and had to work through some problems with access to my SVN repo, which is probably reflective of the sorry state of said repository. As a takeaway, however, note that capistrano2 uses scmusername and scmpassword instead of svnusername/svnpassword.

8) create the database

First you have to create your database user. Again, I know deprec helps with this, but it wasn't immediately obvious to me how to do it. SSHing onto the server and issuing a few commands inside mysql was easy enough though:

mysql> create user general@localhost identified by 'yourpassword';
mysql> GRANT ALL ON *.* TO 'general'@'localhost';

And back on my local machine:

cap deprec:db:create

from here you could do cap deprec:db:migrate, but I wanted a fresh snapshot from production via mysqldump.

9) fire it up

deprec:nginx:restart
deprec:mongrel:restart

It works! Total time elapsed: about three hrs.

This is a good stopping point, since my staging environment is up and running. The next step is to replace Mongrel with Thin -- but that will have to wait for the next post.

Notes on what's where

  • Mongrel Cluster config is in `/etc/mongrelcluster/[appname].yml
  • ninx config is in /usr/local/nginx/vhosts/[app_name].conf

Cheap Rails VPS options

Feb 24 by Andre in Ruby on Rails »

I did some research today on low-cost VPS setups for Rails deployments. My immediate need is to set up some staging environments, but I'm also interested in being able to quickly spawn new production-grade Rails environments as easily (and cheaply) as possible. Note: there's a good discussion on VPS's here in the Rails Business group.

Here are my findings so far:

Who 256mb 512mb 1GB setup fee Rails Stack? Backups Notes
RimuHosting $30 $40 $85 $10-$20 Just ask for it -- Ruby1.8.6 Rails2 Apache2.2 mongrel mysql rmagick "RimuHosting run backups of each VPS once a week. We try to keep 2 copies of the backup" Rimu also gives you 300MB of space on an ftp server -- I use this for rotating mysqldump backups Rimu is the only one of these I've personally used. I have a dedicated box there and VPS's for clients
Linode $19* $29* $60 none None "Backups are your responsibility. You are protected against a hard drive failure on the host, as we utilize hardware RAID 1 mirroring across two drives. However, this is not a substitute for proper backups" *Memory is in odd sizes -- $19 is for 360MB, $29 is for 540MB
SliceHost $20 $38 $70 none They have good instructions for using deprec Cost extra. "At any given time, you have access to 3 images of your system: a daily (less than 24 hours), a weekly (less than 7 days) and a snapshot (variable). Monthly pricing is $5/$10/$15/$30 for 256/512/1024/2048 slices. You can also create a new slice from the backup of another slice (cloning)" *actually have availability right now (2/23/08) on all their slices.
SilverRack $20 $40 $70 none "We have Centos and Debian VPS templates that come with Ruby, Ruby on Rails, Apache 2.2, MySql 5, and ImageMagick installed and ready to go." "We perform nightly backups of all of our customer's VPSs. We keep these backups for 2 days" will give you $10/mo off if you're a member of a Ruby users group
VPSLink $25 $40 $75 none "All of VPSLink's Ruby on Rails templates come with Ruby 1.8.6, Lighttpd, FastCGI, mySQL, and RubyGems 0.9.5 pre-installed"   FastCGI? WTF

Rails stack setup / Application management

For the providers that don't have a Rails stack, there are some good options for setting up your own stack and/or deploying/managing your apps after you get your server running:

  • RailsMachine gem -- Stack setup + App management
  • RubyWorks -- Stack setup -- "RubyWorks implements a load-balanced cluster of Mongrel servers, which in most situations is the best way to deploy a Rails application today. It is packaged as a Yum repository (for RedHat/CentOS) or APT repository (for Debian/Ubuntu)" Works on a range of distros, including Centos 4,5. Uses HAProxy for balancing, doesn't include a web server.
  • Deprec -- Stack setup + App management -- "Deprec is a collection of automated recipes, written in Ruby, for setting up production ready Ruby on Rails servers. This includes everything from creating admin accounts and setting up your ssh keys to compiling and installing the packages required to get a Rails application running on a freshly installed Ubuntu server." Works on Ubuntu 7.10
  • Slingshot gem -- Stack setup + App management -- "a set of recipes, tasks, extensions and plugins that work with Capistrano to setup and configure a server for a Rails Application, quickly, and easily."
  • FiveRun's production stack -- Stack setup -- "provides a fast, easy way to get everything you need to develop and deploy Ruby on Rails applications. RubyStack includes Ruby, Subversion, MySQL, SQLite, ImageMagick and several Ruby Gems, and will optionally install Apache 2.2 with rewrite and proxy support"

Additions / recommendations / corrections? Leave a comment.