简体   繁体   中英

Rails 4: open() doesn't work properly

I have the following line of code in one of my models:

open("|cd lib && /home/rails/jruby/bin/jruby -J-Djava.awt.headless=true -J-Xmx500m -J-Xms500m -J-Djruby.jit.logging=true jasper_order_invoice.rb #{order_id} #{db} #{user} #{pwd} > ../log/jasper.log")

jasper_order_invoice.rb is a script which calls the Java JasperReports library and creates an invoice PDF in tmp/. This used to work very well until I introduced Capistrano as deployment method. The app is now in /home/rails/rails-production/current instead of /home/rails/app . However, the PDF creation doesn't work anymore. No PDF is being created. The strange thing is: It works on my local dev machine and also on the server when I call it directly from the shell, paste the line into irb , or copy the line into an otherwise empty .rb script.

I can see that a java thread starts for about 2 seconds when Rails calls Jruby. It gives me enough time to check the parameters and env variables with ps -exa. Everything seems to be correct. The order_id, db, user and pwd are being passed and the envs are also the same as if I would call the code directly from irb . Paths are also correct.

The log/jasper.log file is unfortunately empty when the Code is being called by Rails. But strange to say it does contain output when I call it from irb .

I have no idea how I could debug this any further. I would especially be very interested in seeing the stdout and stderr, but I don't know why the log file is empty.

The problem was a new environment variable RUBYOPT introduced by the Capistrano setup. This somehow confused jRuby. Adding export RUBYOPT= to the open call before executing jRuby helped.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM