[英]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/. jasper_order_invoice.rb是一个脚本,该脚本调用Java JasperReports库并在tmp /中创建发票PDF。 This used to work very well until I introduced Capistrano as deployment method.
在我引入Capistrano作为部署方法之前,这种方法一直工作得很好。 The app is now in
/home/rails/rails-production/current
instead of /home/rails/app
. 该应用程序现在位于
/home/rails/rails-production/current
而不是/home/rails/app
。 However, the PDF creation doesn't work anymore. 但是,PDF创建不再起作用。 No PDF is being created.
没有创建PDF。 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. 奇怪的是:当我直接从shell调用它,将行粘贴到
irb
或将行复制到否则为空的.rb脚本时,它既可以在我的本地dev机器上运行,也可以在服务器上运行。
I can see that a java thread starts for about 2 seconds when Rails calls Jruby. 我可以看到Rails调用Jruby时,一个Java线程启动了大约2秒钟。 It gives me enough time to check the parameters and env variables with ps -exa.
它给了我足够的时间使用ps -exa检查参数和env变量。 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
. 传递了order_id,db,user和pwd,并且env也与我直接从
irb
调用代码一样。 Paths are also correct. 路径也是正确的。
The log/jasper.log file is unfortunately empty when the Code is being called by Rails. 不幸的是,当Rails调用Code时,log / jasper.log文件为空。 But strange to say it does contain output when I call it from
irb
. 但是奇怪的是,当我从
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,但是我不知道为什么日志文件为空。
The problem was a new environment variable RUBYOPT introduced by the Capistrano setup. 问题是Capistrano安装程序引入了一个新的环境变量RUBYOPT。 This somehow confused jRuby.
这使jRuby感到困惑。 Adding
export RUBYOPT=
to the open call before executing jRuby helped. 在执行jRuby之前,将
export RUBYOPT=
添加到打开的调用中就可以了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.