I'm trying to run a service that uses $HOME and $USER environment variables. I could set them in service itself, but that would only be a temporary solution.
Let's say I have a script test.sh
with following content:
echo $USER
And I run it with start-stop-daemon
to see my results:
$ start-stop-daemon --start --exec `pwd`/test.sh --user guest --group guest --chuid -guest
root
Seems like it does not update environment, maybe that should be reported as a bug?
I have found a nasty hacky solution, which only works (for unknown reason) on my this simple use case:
$ start-stop-daemon --exec /usr/bin/sudo --start -- -u guest -i 'echo $USER'
guest
I'm sure someone else stumbled upon this, I'm interested in clean solution.
$ start-stop-daemon --version
start-stop-daemon 1.13.11+gentoo
Best Answer
This might be the intended behavior. The manual page shows an
--env
option forstart-stop-daemon
:The author used
$HOME
in the example, which I take to mean that it wouldn't normally set it. I don't see any other options for updating the environment of the process you're starting.Try running
start-stop-daemon
like this:Another alternative would be to run the script under
sudo
:sudo
will automatically set$USER
, and the-H
option tells it to set$HOME
as well. I ran both of these with my owntest.sh
that prints the value of thse variables, and both updated them as desired. I'm partial to the first because it doens't add another program to the mix, but that's just me.