About "couldn't find HOME environment" problem

Hi,

Some few people (including me) reported “couldn’t find HOME
environment” problem in this ML and trac(for example ticket #500).
Ticket #500 was closed by the reason “This is an issue with your
server setup. It’s not a problem with Radiant.”, but I don’t think so.
I believe this is because
lib/plugins/extension_patches/lib/generator_base_extension.rb does
“require ‘rails_generator’”. Dispatchers(.cgi, .fcgi and .rb) of
Radiant don’t need this file and I think these must not load
rails_generator. The problem happens to people using CGI or Apache(or
Lighttpd)/fast-cgi in most cases because HOME environment is not a
standard CGI metavariable.

I think the solution is that move
lib/plugins/extension_patches/lib/generator_base_extension.rb to
lib/generators/generator_base_extension.rb and load it in
script/generate etc. Is it right? I am not familiar with rails, sorry
if I am wrong.


Keita Y.

keita wrote:

standard CGI metavariable.
How does generator_base_extension.rb affect the HOME environment
variable? Does the default Rails generator set the HOME environment
variable in environment.rb? I don’t believe it does. So again this isn’t
a problem with Radiant. It’s a problem with the way your hosting
environment is configured.

We could certainly add a few lines to environment.rb that were commented
out like this:

Depending on how your envoronment is set up you may need to uncomment

the following line and enter the correct path to your home directory:

#ENV[‘HOME’] = ‘/path/to/your/home/directory’

Would this be helpful?


John L.
http://wiseheartdesign.com

John,

I had this very same problem last night and the only way to solve it
was to use a line just like you suggested:

ENV[‘HOME’] = ‘/home/xyz/’

My environment is Litespeed 3.03 running on Centos. Took me a while to
figure it out. Maybe a gotcha section in the install docs would
help.

Sincerely,

AEM

I performed the following

  • cd ~user/myRadiantApp
  • ‘unset HOME’ and verified it was gone
  • ‘echo ~’ returns /var/www/vhosts/myDomain
  • ‘pwd’ returns /var/www/vhosts/myDomain/myRadiantApp
  • ‘emacs test1.rb’ and pasted in your code
  • ‘ruby test1.rb’ ran with no errors

It is not very clear to me where home should be. My Fedora Core 4 system
running Plesk 8.1 seems to automatically set HOME when ‘su user’. I do
not
see HOME as providing any useful information. As far as I can see, the
only
thing that matters is where myRadiantApp is.

For example, I could have put myRadiantApp under httpdocs. Instead I
setup
my system is set up as follows
/var/www/vhosts/myDomain/ <----- ENV[‘HOME’] normally set by Linux
|—httpdocs/ ----->ln -s /var/www/vhosts/myDomain/myRadiantApp/public
httpdocs
|—myRadiantApp/
|—public/
| |—dispatch.fcgi
|—vendor/
|-radiant (I froze radiant so all application code owned by
same
user/permissions)

I do not think you can count on where HOME is relative to myRadiantApp
before I unset HOME linux has set it to /var/www/vhosts/myDomain

On 4/27/07, keita [email protected] wrote:

  1. It is radiant issue that Radiant’s dispatcher loads
    rails/railties/lib/rails_generator.rb, and other rails applications’
    dispatchers don’t load rails_generator.rb.

  2. I believe dispatchers don’t need to generate any code and must not.

I must agree with you, Keita. Nice writeup

Hi John,

Thank you for reading my mail. but I can’t agree server configuration
causes this problem. I explain more details.

First, CGI and Apache/fast-cgi doesn’t set HOME variable if you don’t
set SetENV. So dispatchers in these doesn’t know HOME in most cases.
Webrick or Mongrel users are O.K. because know HOME in most cases. I
agree that this is a server specific and configuration issue. Radiant
doesn’t need to care it.

How does generator_base_extension.rb affect the HOME environment
variable?

generator_base_extension.rb gets HOME environment as follows(radiant
0.6.0 / rails 1.2.3):

(lib/plugins/extension_patches/lib/generator_base_extension.rb)
require ‘rails_generator’

(rails/railties/lib/rails_generator.rb)
require ‘rails_generator/lookup’
Rails::Generator::Base.send(:include, Rails::Generator::Lookup)

(rails/railties/lib/rails_generator/lookup.rb:51)
Rails::Generator::Lookup.included

(rails/railties/lib/rails_generator/lookup.rb:98)
Rails::Generator::Lookup::ClassMethods.use_component_sources!

(rails/railties/lib/rails_generator/lookup.rb:25)
Dir.user_home

If ENV[‘HOME’] is nil (this is the case of CGI and Apache/fast-cgi),
it calls File.expand_path ‘~’. But File.expand_path needs to know
HOME, check it by the following commands:

unset HOME
ruby -e ‘File.expand_path “~”’

This is the reason of the error message (but this isn’t the root cause
of the problem, I think). so, if rails dispatchers(CGI,
Apache/fast-cgi) load rails/railties/lib/rails_generator.rb, then
happen the error.

Does the default Rails generator set the HOME environment
variable in environment.rb?

No. Rails generator(like script/generate) doesn’t read
config/environment.rb but config/boot.rb. This problem is about
dispatchers(.fcgi, .cgi, .rb), not generator.

I believe normally rails applications don’t need to set HOME in
environment.rb. I checked Mephisto, Typo and Beast. Such rails
applications don’t need to set HOME in CGI and Apache/fast-cgi because
these dispatchers don’t require rails/railties/lib/rails_generator.rb.

I think rails generators are for spitting out Ruby code. Why do
radiant’s dispatchers need to generate new code? I can’t understand
the advantage and I believe dispatchers don’t need to generate any
code.

If it is right, this is the waste misloading problem of
Radinat::Initializer. Radinat::Initializer.run(:process, &config) in
config/environment.rb loads lib/plugins/extension_patches/init.rb and
it requires
lib/plugins/extension_patches/lib/generator_base_extension.rb.
I think this is the root cause of the problem. Please try to reproduce
the problem by unsetting HOME and exec the following code:

require “pp”
begin
require ‘config/environment.rb’
rescue Exception
pp $@
end

Summary of my opinion:

  1. I agree that ENV[‘HOME’] == nil is server specific(CGI,
    Apache/fast-cgi) and hosting configuration issue. So radiant doesn’t
    need to care it.

  2. rails/railties/lib/rails_generator.rb need to know HOME.

  3. It is radiant issue that Radiant’s dispatcher loads
    rails/railties/lib/rails_generator.rb, and other rails applications’
    dispatchers don’t load rails_generator.rb.

  4. I believe dispatchers don’t need to generate any code and must not.

  5. If 4 is true, the cause of this problem is waste loading of
    generator_base_extension.rb and rails/railties/lib/rails_generator.rb
    for dispatchers. Generators like script/generate need to requires
    rails_generator.rb and dispatchers don’t.

For above reasons, I conclude this is a problem of radiant. Is it
right? My arguments is based on the assumption of 4, so I am sorry for
wasting your time if this assumption is wrong. I don’t think of the
advantage that dispatchers act as generator because I am not familiar
with rails.


Keita Y.

keita wrote:

For above reasons, I conclude this is a problem of radiant. Is it
right? My arguments is based on the assumption of 4, so I am sorry for
wasting your time if this assumption is wrong. I don’t think of the
advantage that dispatchers act as generator because I am not familiar
with rails.

OK, I see what you are saying now. Please reopen the ticket and submit a
patch for it if you can.


John L.
http://wiseheartdesign.com