Posts Tagged ‘passenger’

Getting paperclip to work with passenger not running under root

After moving from Thin to passenger to save memory on one of my VM (with only 256mb every byte counts… ) I could not get paperclip to re-size images.

This was the error I got:
[paperclip] An error was received while processing: #
[paperclip] Processing medium # in the thumbnail processor.
[paperclip] An error was received while processing: #

The problem was permissions on the rails tmp directory. When I deploy using Capistrano the RAILS_ROOT/tmp directory is cleared-out so the .ruby_inline setup is re-initialized by the root user. Since I don’t run Passenger as root this throws the error above. Here is how I get around this without logging in to the server after deploy and executing a chown command:

In my RAILS_ROOT/config/environments/production.rb file I added this to the bottom:

temp = Tempfile.new(‘ruby_inline’, ‘/tmp’)
dir = temp.path
temp.delete
Dir.mkdir(dir, 0755)
ENV[‘INLINEDIR’] = dir

This replaced the old setup that I had:
ENV[‘INLINEDIR’] = File.join(RAILS_ROOT, ‘tmp’)

So now I delete the .ruby_rails directory with the wrong permissions and create a new directory with the rails user… nice!

Advertisements