ImageScience and mod_fcgid

March 22nd, 2007

Recently converting a bunch of rails apps to AttachmentFu from ActsAsAttachment to make use of ImageScience i found that anything that refered to a model that has a: 'has_attachment' in it caused rails to fail with a cryptic message:

ActionView::TemplateError (exit) on line #41 of app/views/pages/section_home.rhtml:
38:           <h2>Story</h2>
39:           Scobie sponsors many of Tasmania's community organisations...
40:         </div>
41:         <img src="/images/stories/1.jpg" border="0" alt="Story" />
42:       </a>
43:     </div>
44:     <div class="story">

/usr/lib/ruby/gems/1.8/gems/RubyInline-3.6.2/inline.rb:70:in `exit'
/usr/lib/ruby/gems/1.8/gems/RubyInline-3.6.2/inline.rb:70:in `rootdir'
/usr/lib/ruby/gems/1.8/gems/RubyInline-3.6.2/inline.rb:84:in `directory'
/usr/lib/ruby/gems/1.8/gems/RubyInline-3.6.2/inline.rb:257:in `so_name'
/usr/lib/ruby/gems/1.8/gems/RubyInline-3.6.2/inline.rb:291:in `load_cache'
/usr/lib/ruby/gems/1.8/gems/RubyInline-3.6.2/inline.rb:627:in `inline'
/usr/lib/ruby/gems/1.8/gems/image_science-1.1.1/lib/image_science.rb:84
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require'
/usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require'

etc...

Error was quite bizare especially as line 41 refered to a static file that gets served up by apache, taking out that line would cause errors on other lines of the html.

Anyhow after much debugging and looking through the source for ImageScience and RubyInline i noticed that RubyInline was not generating the shared object for ImageScience.

The default in my case was:
ENV['HOME']/.ruby_inline/Inline_ImageScience_aa58.so

That seemed like it should work, i expected fastcgi would have the HOME environment variable set. I was wrong...

as a quick test i edited dispatch.fcgi to include:
ENV['HOME'] = '/home/username'

Alas it worked!

I didn't think it was ideal to have to edit dispatch.fcgi for each rails app,

some quick research led me to find the Apache module mod_env.
PassEnv directive which could be set in the global 'server config' looked usefull!

But no... Apache reported: [warn] PassEnv variable HOME was undefined

SetEnv also didnt work in any of the contexts (server config, virtual host, directory, .htaccess)

Now because im running multiple clients and accounts on this server i use suexec.

It seems suexec blocks Environment variables that are not in its whitelist (which is compiled into it).

I was already manually compiling suexec (to replace the one from the Debian package) so added the following: /usr/src/apache2-2.2.3/support/suexec.c

    "TZ=",
+    "HOME=",
+    "RAILS_ENV=",
    NULL

recompiled, coppied to correct place and reloaded apache

"That has to solve it" I thought to myself...

Wrong again!

I had hit another brick wall, this time it was mod_fcgid.

It appeared it was blocking my attempts to set an environment variable in apache. The only option the module has for environment variables is: DefaultInitEnv and that is done in the 'server config' context, which is useless for my needs.

At this point i thought it May be posible to hack mod_fcgid to pass the environment variables i want, but i had already spent way too much time on this.

So i will continue to set ENV['HOME'] in dispatch.fcgi till i find a better solution for my fastcgi rails apps.

If anyone has a better solution to this i'd love to hear about it!

FYI: The majority of the rails apps on the server are run under mongrel, fastcgi is just used for the ones that don't get much traffic and/or are for testing.

5 Responses to “ImageScience and mod_fcgid”

  1. Jos Says:
    I am running into the same problem with attachment_fu and instantrails. After installing the plugin and running 'rake test:plugins PLUGIN=attachment_fu' it begins running the test, goes through creating tables and initializing schema, etc, and on the line columns("schema_info") i get below it: Define INLINEDIR or HOME in your environment and try again rake aborted! Command failed with a status (1): [C:/InstantRails/ruby/bin/ruby -Ilib;test "...] I have no idea what this means, as I am new to rails and web development. Does this seem like a problem similar to yours? Have any ideas on what to do?
  2. AaronT Says:
    Jos: Your issue is that ImageScience is not supported on windows, because it depends on RubyInline which needs a compiler. You could try and add following to environment.rb ASSET_IMAGE_PROCESSOR = :rmagick || :none OR unsintall ImageScience gem then try again
  3. Nathan Says:

    Sorry, OP, I've been searching everywhere for a solution to this and I've come across your page finally but this did not solve my problem. I'm getting compile errors like AaronT suggests, tested on vista and xp.

    If you have got it working can you suggest what compiler you have installed?

  4. ktec Says:

    If it helps at all, having just read this post, i tried uninstalling the image_science gem and now my migrations work again. Before i did this i was getting the "Define INLINEDIR or HOME in your environment and try again" error when attempting to run a migration that would insert user data into my user table, therefore nothing to do with image processing...

  5. Kevin McNamee Says:

    Having similar problems with Rails + Oracle and LDLIBRARYPATH. This link my provide some insight http://wiki.rubyonrails.com/rails/pages/HowToUseOracleWithFastCGI

Sorry, comments are closed for this article.