How to set environment variables in Rails context

Discussion in 'Ruby/Rails' started by nicksnels, Nov 11, 2007.

  1. nicksnels

    nicksnels New Member

  2. mistwang

    mistwang LiteSpeed Staff

    Under Configuration->server->Ruby Rails tab.
  3. nicksnels

    nicksnels New Member

    I have found it. Do I just add JAVA_HOME=/usr/java/jdk1.5.x/, to set the environment variable? Thanks.

    Kind regards,

    Nick
  4. mistwang

    mistwang LiteSpeed Staff

    Yes, that is it.
  5. nicksnels

    nicksnels New Member

    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
  6. mistwang

    mistwang LiteSpeed Staff

    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. nicksnels

    nicksnels New Member

    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. nicksnels

    nicksnels New Member

    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
  9. mistwang

    mistwang LiteSpeed Staff

    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. nicksnels

    nicksnels New Member

    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
  11. mistwang

    mistwang LiteSpeed Staff

    If that is the case, you also need to check the permission of the parent directories of the destination folder.
  12. nicksnels

    nicksnels New Member

    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

Share This Page