Dreamhost migrations & Padrino

Dreamhost recently migrated some shared hosting servers, and it broke my padrino instances. Here's how I fixed it.

Most of my sites were fine - ones on rails had no problems at all, and some of my older sites were fine with the change. But my padrino instances for some reason decided they were not happy in their new home.

The setup

This site is currently running on padrino. It is using a modified version of the .htaccess and dispatch.fcgi found in Padrino Recipes, which has a recipe handily entitled Dreamhost Plugin. It is hosted on a Dreamhost shared server.

The problem

Finding the problem is, of course, part of the problem. When the only error message you see is

Padrino application failed to start properly

...debugging is made that slight bit harder. None of the logs - neither dreamhost's server logs, running dispatch.fcgi on the command line, or padrino's inner logs seemed to tell me anything of use.

The investigation

Well, here's the first tip, courtesy of a site devoted to Sinatra recipes: In your dispatch.fastcgi, redefine what STDOUT and STDERR point to!

fastcgi_log = File.open("/path/to/my_fastcgi.log", "a")
STDOUT.reopen fastcgi_log
STDERR.reopen fastcgi_log
STDOUT.sync = true

After doing that, I found out that the error was caused by a missing gem. But wait! I've run bundle install thousands of times, surely this gem could not be missing? So I opened irb and, lo and behold, it was there (the missing gem in my case was Thor - your missing gem may be different)

The solution

So... when is a missing gem not a missing gem? It turns out that Dreamhost munges your environment. The Padrino recipe linked above states that GEM_HOME and GEM_PATH need to be set, but it only sets GEM_HOME - presumably because GEM_PATH was working fine. Well, now it's not - so you need to set GEM_PATH to both your GEM_HOME, and to Dreamhost's central gem repository. I found the hint to this on Dreamhost's wiki. Of course, I tweaked it slightly:

ENV['GEM_HOME'] = '/home/USERNAME/.gems'
ENV['GEM_PATH'] = ENV['GEM_HOME'] + ":" + '/usr/lib/ruby/gems/1.8'

Note that if you have RVM working, these lines will need to be tweaked even more.

Hope you found that useful!