Problems with God (, RubyInline and Rails)
I started to use the god process monitoring tool to lighten the load of managing some tiny Ruby on Rails services I’ve written at work. Prior to this rebooting a server or, god forbid, an application error would result in a downtime until I manually checked each service, invariably being several hours post error. God has proved a solution to this problem, aside from a small problem I had involving RubyInline.
The setup: a small service which associates files with a string for retrieval. You pass the service a string and a file, and it will save them; pass back the string and get your file back. A remote key-value service, really.
The problem first exposed itself as a loading error:
LoadError in SomeResourcesController#index Expected /home/redacted/deploy/20080629152441/app/models/redacted.rb to define Redacted
This was strange, as the rb file contained the class required. I restarted the mongrels and tried again. I was now greeted by a different hairy specimen:
The culprit is obviously RubyInline, but beyond this the error is bereft of useful information.
I used attachment_fu (good tutorial) to manage the uploaded file, which in turn uses ImageScience, which, finally, uses RubyInline. RubyInline allows C code to be included in Ruby code, which is then compiled into a temporary .so file and can be used from Ruby. ImageScience uses RubyInline to generate interface code to the C image libraries it uses.
Further, RubyInline uses a temporary folder to store its generated .so files; it requires this folder be read/write/execute for the user it is running under, and not-writable by anyone else. This restriction is security-driven, to prevent malicious code being switched in. I digress.
The salient fact is this temporary folder is configured by setting ENV[‘INLINEDIR’] in your Rails configuration. If this setting isn’t found, the location falls back to ENV[‘HOME’]/.ruby_inline.
When running my service from the command line, it was inheriting the environment variables from the shell, specifically the HOME variable. With the service under god’s command the HOME environment variable is not set for whatever reason, meaning RubyInline freaks out when it can’t find its temporary folder.
After all this fuss, the solution is simple: modify your config/environments/production.rb to add the environment variable RubyInline is expecting. Like this: