Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have two servers, they're identical (I believe), production and staging servers.

And I have upstart script in /etc/init/ folder.

description "Discoure process"

setuid deploy
setgid deploy

respawn
respawn limit 3 30

start on runlevel [2345]
stop on runlevel [06]

script
exec /bin/bash <<'EOT'
  echo \"$HOME/.rbenv\"

  cd /home/deploy/discourse/current

  bundle exec bluepill load config/discourse.pill --no-privileged --base-dir tmp/bluepill --logfile log/bluepill.log
EOT
end script

On the staging server it works well, but when I'm running that script on production server then the HOME variable is empty, the code echo "$HOME/.rbenv" is evaluating to "/.rbenv"

What might be a problem here? Thanks

share|improve this question
    
I don't know the root cause, but why not set it first, statically though? –  Jobin Dec 20 '13 at 10:15
    
Why the cumbersome bash script? It looks like (da)sh would interpret it perfectly fine. –  David Foerster Dec 21 '13 at 19:29
add comment

2 Answers

up vote 5 down vote accepted
+100

Please read this question on stackoverflow.com.

And this answer by user grawity on superuser.com.

As I understand you should not use $HOME in init.d, because it is not clear which users home to use, until this user logs in.

You can use little hack, to get home folder of user myuser in your script

su - myuser -c /usr/bin/env | grep HOME

It is better to use script below, because usually there can be other HOME_* folders. Such as JAVA_HOME etc.

su - myuser -c /usr/bin/env | grep "^HOME="
share|improve this answer
add comment

Seems like the $HOME is being interpreted before it goes to bash? I would try one of the following. Either add:

env HOME=/home/MyName

to the code just after the description.

Or move the code from inside the script block to another script file with:

#! /bin/bash

as line 1. Then have

exec /path/to/my/script.sh
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.