Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paperclip with JRuby

Recently I was adapting my rails app to run on JRuby. One of problems that i've encountered was with Paperclip. Paperclip uses Cocaine to run command line tools like ImageMagick and it uses Process.spawn, which results in:

Errno::ECHILD: No child processes - No child processes
                 waitpid at org/jruby/RubyProcess.java:512
                 waitpid at org/jruby/RubyProcess.java:497
                 waitpid at /home/cthulhu/.rvm/gems/jruby-1.6.7.2/gems/cocaine-0.3.0/lib/cocaine/command_line/runners/process_runner.rb:21
                    call at /home/cthulhu/.rvm/gems/jruby-1.6.7.2/gems/cocaine-0.3.0/lib/cocaine/command_line/runners/process_runner.rb:9
                 execute at /home/cthulhu/.rvm/gems/jruby-1.6.7.2/gems/cocaine-0.3.0/lib/cocaine/command_line.rb:77
                     run at /home/cthulhu/.rvm/gems/jruby-1.6.7.2/gems/cocaine-0.3.0/lib/cocaine/command_line.rb:55
                     run at /home/cthulhu/.rvm/gems/jruby-1.6.7.2/gems/paperclip-3.2.0/lib/paperclip/helpers.rb:29

Is there any way to make Paperclip work smoothly with JRuby? I'm running my app on linux only, so i don't mind using linux native tools like ImageMagick.

Rails 3.2.8, JRuby 1.6.7.2

like image 802
cthulhu Avatar asked Sep 12 '12 11:09

cthulhu


2 Answers

This is still a problem in JRuby 1.7. There is a caveat for JRuby noted on the Cocaine Github page that defines this as a JRuby problem. For me, as of this writing, the only way to get it to work was to use

Cocaine::CommandLine.runner = Cocaine::CommandLine::BackticksRunner.new

as noted in the Runners section of the Cocaine Github page.

like image 141
nathan Avatar answered Sep 22 '22 19:09

nathan


After some digging in Paperclip and Cocaine code I wrote an initializer which monkey-patches Cocaine to use BackticksRunner when on JRuby

if RUBY_PLATFORM == 'java'
  module Cocaine
    class CommandLine
      def best_runner
        BackticksRunner.new
      end
    end
  end
end

However I'm stil looking for a cleaner solution.

like image 33
cthulhu Avatar answered Sep 25 '22 19:09

cthulhu