capistrano-ext-textdrive

Posted on February 20, 2007

I’ve finally found a workable set of deployment practices for getting my little rails apps up and running in shared hosting at TextDrive. None of the actual mechanics are particularly en vogue these days — I’m just using plain old lighttpd with external fcgi processes.

What is kind of fun, though, is that I’ve reduced almost all of the duplication across my deploy.rb files, so now they look like this:


require 'capistrano/ext/textdrive'

set :application, 'reading'
set :domain,      'matthewtodd.org'

This is exceedingly pleasing to me, because these are the only 2 settings I’d ever change from app to app — precisely what belongs in an application-specific configuration file.

Herewith, a description of the behavior that require line provides:

textdrive_configure_lighttpd

Run this once for your account.

  • creates lighttpd configuration file and supporting directory structure for virtual hosts, logs and PID files
  • writes an rc.d start/stop/restart script for lighttpd, and a crontab entry to run it at server startup

[code]

textdrive_after_setup

Run this once for your application. An after_setup task has been defined to call this automatically, but if you write your own, you’ll clobber it — see this test case — so be sure to call textdrive_after_setup if you write a custom after_setup task.

  • creates an empty mysql database named "#{user}_#{application}" and writes "#{shared_path}/database.yml" referencing it
  • writes an rc.d start/stop/restart script for the application and a crontab entry to run it at server startup
  • writes a lighttpd virtual host configuration and restarts lighttpd
  • configures apache to proxy requests for "#{application}.#{domain} to lighttpd

[code]

textdrive_after_update_code

Run this every time you deploy. An after_update_code convenience task has been defined just as above, with the same clobberability caveats.

  • create symlinks to "#{shared_path}/database.yml" and "#{shared_path}/sockets" from the appropriate places under "#{release_path}"

[code]

If you’d like to try it out

This code’s packaged as a gem, but I haven’t released it anywhere yet. So:


svn export http://matthewtodd.org/svn/public/capistrano-ext-textdrive
cd capistrano-ext-textdrive
rake install

And then your deploy.rb is going to need a few more lines than mine, since I made the defaults fit my needs and tastes. It will probably end up looking something like this:


require 'capistrano/ext/textdrive'

set :application,   YOUR_APPLICATION
set :domain,        YOUR_DOMAIN
set :user,          YOUR_USERNAME
set :lighttpd_port, YOUR_LIGHTTPD_PORT
set :repository,    YOUR_REPOSITORY_PATH

Do be sure to read through the gem code first to understand what it’s doing — I expect things will generally work fine, but it would be a shame to run into trouble with it.

A few notes

One last unautomated bit is that you’ll need to set ProxyPreserveHost On for each Apache virtual host into which you’re deploying rails apps this way. (See steps 10-12 in this bit of TextDrive documentation.)

Most of this approach comes from Installing a Rails Application at TextDrive, in the TextDrive knowledge base.

See also Shovel, from Geoffrey Grosenbach.

Running

Posted on February 14, 2007

I decided a while back to give myself a little bit of routine by training for the Kilimanjaro Half Marathon. I hadn’t ever really run more than 3 miles before, but so far, so good, and the race is coming up soon now — just 2½ weeks!

The actual race route runs along a very narrow, busy road, so I’ve been running instead up into the villages above town. After about 4k the pavement turns into dirt, and I pass through coffee fields and over a gorgeous rushing river, just like something you’d see in the Smokies. Lots of kids are walking home from school at the same time — sometimes they laugh and run with me, sometimes they yell “Mzungu!” and ask for money, but all in all it’s pretty fun.

On a geek note, one thing that’s made a huge difference in my training is this GPS doohickey Dad gave me. It figures out how far I’ve gone (there’s no way I could tell that otherwise, since we couldn’t drive these routes) and how fast I’m going — and it even beeps when I’ve gone halfway so I’ll know to turn around and go home!

GPS doohickey

I suppose that’s all there is to say for now, but I’ll be sure to write about how the race goes!

Wedding reception, Moshi style

Posted on February 12, 2007

He's Looking at Me

More pictures on Flickr.