Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  11] [ 0]  / answers: 1 / hits: 13687  / 2 Years ago, sun, march 20, 2022, 2:31:10

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


More From » upstart

 Answers
0

Read this question on stackoverflow.com and this answer by user grawity on superuser.com



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



Quote from POSIX specification:



HOME
The system shall initialize this variable at the time of login to be a pathname
of the user's home directory. See <pwd.h>.


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="

[#27930] Sunday, March 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
measord

Total Points: 259
Total Questions: 131
Total Answers: 106

Location: Venezuela
Member since Sun, Oct 2, 2022
2 Years ago
measord questions
Wed, Jul 14, 21, 21:39, 3 Years ago
Mon, May 16, 22, 21:12, 2 Years ago
Mon, Oct 11, 21, 03:11, 3 Years ago
Sun, Apr 17, 22, 21:22, 2 Years ago
;