How to set environment variables in Rails context

#5
The reason I asked this is because I have a script that tries to open a Java Virtual Machine within a Rails project. The code is:

require 'rjb' #Ruby Java Bridge
Rjb::load('lib/itext-2.0.6.jar')

It runs on the latest version of Litespeed and Centos 4.4. I have set the following variables in the Rails Context (as indicated by your previous response):

JAVA_HOME='/usr/java/jdk1.5.x/'
LD_LIBRARY_PATH='/usr/java/jdk1.5.x/jre/lib/i386/:/usr/java/jdk1.5.x/jre/lib/i386/client/:./'
CLASSPATH='path_to_file/lib/itext-2.0.6.jar'

The code works under Webbrick on the same Linux machine. But fails to work with Litespeed. I get the following error:

A RuntimeError occurred in order#process_order:

can't create Java VM
[RAILS_ROOT]/app/models/pdf.rb:2:in `load'

Since it works under Webbrick, I guess it is a problem with Litespeed. But I can't figure it out. All help is welcome. Thanks.

Kind regards,

Nick
 

mistwang

LiteSpeed Staff
#6
Maybe there are other required environment variable. Or the memory limit need to be increased as JVM is pretty demanding on memory. you need to get a better idea about what exactly goes wrong, try "strace -f" the ruby process that is going to process the request using a JVM.
 
#7
Thanks for your reply. Just send my strace output to support at lite... Hope it tells you something more about my problem. Thanks.

Kind regards,

Nick
 
#8
Thanks for the tip. Increasing the memory limit with quite a bit did the trick. The Java VM gets started. Now I have encountered another strange error.

I have a file which is chmod 644 and nobody:nobody. I want to copy it in Rails (FileUtils.cp(source, destination)) to the home directory of a user. The directory is also nobody:nobody. But this doesn't work, I get the error:

A Errno::EACCES occurred in order#order:

Permission denied - /home/user/pdf/1.pdf
/usr/local/lib/ruby/1.8/fileutils.rb:1402:in `stat'

Any ideas what may be causing this? Thanks.

Kind regards,

Nick
 

mistwang

LiteSpeed Staff
#9
You need to check which user the ruby process run as. Usually, it is same as the owner of the public/ folder. You can make the public folder owned by nobody.
 
#10
Thanks for the quick reply, unfortunately it didn't work. My ruby processes al run as user nobody. So I changed the destination folder to nobody:nobody and 777, but that also didn't work. Also changed it to the user of the public folder but no luck either. BTW writing to the public folder works like a charm. Only copying the file put in the public folder to my home directory proves difficult.

Kind regards,

Nick
 
#12
Hi, that did the trick. Everything is working now. Thank you very much for your help. Couldn't have solved it without you. Thanks.

Kind regards,

Nick
 
Top