Rails 4:open()无法正常工作

时间:2021-09-29 03:43:24

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.

jasper_order_invoice.rb是一个调用Java JasperReports库并在tmp /中创建发票PDF的脚本。在我将Capistrano作为部署方法介绍之前,这曾经非常有效。该应用程序现在位于/ home / rails / rails-production / current而不是/ home / rails / app。但是,PDF创建不再起作用。没有创建PDF。奇怪的是:当我直接从shell调用它时,它可以在我的本地开发机器上运行,也可以在服务器上运行,将行粘贴到irb中,或者将行复制到一个空的.rb脚本中。

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.

我可以看到当Rails调用Jruby时,java线程启动大约2秒。它给了我足够的时间来检查ps -exa的参数和env变量。一切似乎都是正确的。正在传递order_id,db,user和pwd,并且envs也与我直接从irb调用代码相同。路径也是正确的。

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.

遗憾的是,当Rails调用Code时,log / jasper.log文件是空的。但奇怪的是,当我从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.

我不知道如何进一步调试这个。我特别感兴趣的是看到stdout和stderr,但我不知道为什么日志文件是空的。

1 个解决方案

#1


0  

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.

问题是Capistrano设置引入的新环境变量RUBYOPT。这在某种程度上混淆了jRuby。在执行jRuby之前将导出RUBYOPT =添加到open调用帮助。

#1


0  

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.

问题是Capistrano设置引入的新环境变量RUBYOPT。这在某种程度上混淆了jRuby。在执行jRuby之前将导出RUBYOPT =添加到open调用帮助。