deprec2: Mongrel, nginx, Rails, mysql on Ubuntu 7.1
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