Andrew's (Tumbling) Interwebdiary

A Hideous Triumph of Form and Function

Jun 17

Phusion Passenger migration issues solved!

I recently decided to move a couple of our sporadically used internal applications over to Phusion Passenger (a.k.a mod_rails a.k.a. mod_rack a.k.a. mod_rack that-runs-but-probably-shouldn’t-WSGI). I ran into two problems which I thought would showstopping issues that were Apache related, but upon looking into it where things special to one of my Rails apps.

Long story short: both of these had to do with the fact that I was moving an app that had run on mongrel as a real user (I mentioned these were internal, right? :) ) into Apache’s environment, which doesn’t have a .bashrc or home directory (and this is a good thing).

For the record, the OS is Ubuntu Server (Gutsy Gibbon), so if you’re using something else, make sure to double check the paths I give. Also, the Rails application is the RadiantCMS.

Ruby-Java Bridge

We’re using the Ruby-Java Bridge to use a Java Library and weren’t yet confident in JRuby or, more exactly, how other parts of the application might react.

Anyway, the first error I encountered was:

RuntimeError: can't create Java VM

… which happens when the JAVA_HOME environment variable isn’t specified. I had been setting this in the user’s .bashrc, but this was no longer an option. Instead, I added this to the end of config/environments/production.rb:

ENV['JAVA_HOME'] = "/usr/lib/jvm/java-1.5.0-sun/"

Page Attachments Extension -> AttachmentFu -> ImageScience -> RubyInline

My Radiant instance is using the Page Attachments extension which uses AttachmentFu, which in turn can use a couple of different image libraries to handle image scaling. In this case, I had configured it to use ImageScience, which in turn uses RubyInline. RubyInline compiles C written inside of Ruby often times to produce bindings to C libraries or more performant code. However, it needs a place to store these object files. That’s what this error means:

Define INLINEDIR or HOME in your environment and try again

When you’re running as a user, HOME is set correctly. This line (again in config/environments/production.rb) fixes it:

ENV['INLINEDIR'] = File.join(RAILS_ROOT,'tmp','ruby_inline')

Don’t try to set it to /tmp — RubyInline won’t write to anywhere that’s group or world writable. Fortunately, the application’s tmp file is a handy place for this.

Conclusion

And there we have it. Now I no longer have to worry about having a bunch of idle processes hanging around for months before their used again all the while blocking up precious memory. Also, configuration is so much simpler now. I was able to remove a whole lot of rewrite and proxy rules, which while comprehensible, where also complex.

So huzzah for Passenger! While it may not replace Mongrel in every use case, it takes the cake with sporadically used, small applications.