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
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With