Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

couldn't find HOME environment #58

Closed
anlek opened this issue Aug 22, 2014 · 11 comments
Closed

couldn't find HOME environment #58

anlek opened this issue Aug 22, 2014 · 11 comments

Comments

@anlek
Copy link

anlek commented Aug 22, 2014

Hey, great work with this gem, however I'm having an issue when deploying it in Production (Ubuntu 14.04). I'm getting:

lib/image_optim/config.rb:13:in `expand_path': couldn't find HOME environment -- expanding `~' (ArgumentError)

My user does have a home directory and when I run console, I get this:

irb(main):002:0> ENV["HOME"]
=> "/home/deployer"
irb(main):003:0> File.expand_path("~")
=> "/home/deployer"

Not sure what's happening.

@anlek
Copy link
Author

anlek commented Aug 22, 2014

I even tried settting XDG_CONFIG_HOME but still same error.

@anlek
Copy link
Author

anlek commented Aug 22, 2014

I was able to fix it by changing like 13:
from:

CONFIG_HOME = File.expand_path(ENV['XDG_CONFIG_HOME'] || '~/.config')

to:

CONFIG_HOME = File.expand_path(ENV['XDG_CONFIG_HOME'] || "#{ENV["HOME"]}/.config")

@toy
Copy link
Owner

toy commented Aug 22, 2014

Hi Andrew.
You did not specify which stack do you use. It can be the same issue as explained at lsegal/yard#708.

Exception tells that you don't have HOME variable defined, so ENV['HOME'] is nil and "#{ENV["HOME"]}/.config" will expand to '/.config'.

Try following in console (it should raise the same exception):

ENV.delete('HOME')
File.expand_path('~')

And try to log value of ENV['HOME'] in production environment.

@anlek
Copy link
Author

anlek commented Aug 22, 2014

I'm using Rails 4.1.5 and Ruby 2.1.2
The problem is that when I go into rails c -e production and run ENV["HOME"] I still get the home directory.

@toy
Copy link
Owner

toy commented Aug 22, 2014

If you run rails c -e production from login session ruby will get HOME variable.
Under which user does rails run in production? Does that user have a home directory?

I understood the problem and I assume that it should be harmless to ignore exception when finding home/config directory, probably better to show warning.

@anlek
Copy link
Author

anlek commented Aug 22, 2014

I agree, a warning would be great, but at the moment, I just need it to work.

My script that runs it (under /etc/init.d/unicorn_app) starts with:

CMD="cd /data/web/my_site/production/current; bundle exec unicorn -D -c /data/web/my_site/production/shared/config/unicorn.rb -E production"
AS_USER=deployer
set -u
# ....other settings...
# ...call to CMD if start has been called

CMD is the actual command that gets called when it starts...

@toy
Copy link
Owner

toy commented Aug 22, 2014

CMD="cd /data/web/my_site/production/current; env HOME=/dev/null bundle exec unicorn -D -c /data/web/my_site/production/shared/config/unicorn.rb -E production"

@anlek
Copy link
Author

anlek commented Aug 22, 2014

I'll update my script to reflect your recommendation.
Would that mean that I can't use the config folder?

@toy
Copy link
Owner

toy commented Aug 22, 2014

Does deployer have a home folder: echo ~deployer
You can set HOME to any path, but if you use /dev/null there will be no way for image_optim global config.

@toy
Copy link
Owner

toy commented Sep 7, 2014

@anlek Please confirm that master fixes this issue for you, you should see a warning with «couldn't find HOME environment».

@toy
Copy link
Owner

toy commented Oct 4, 2014

@anlek Please reopen if needed.

@toy toy closed this as completed Oct 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants