I have a service that runs as root:
[Unit]
Description=my service
After=docker.service network-online.target
Requires=docker.service network-online.target
[Service]
TimeoutStartSec=0
RestartSec=60
Restart=always
User=root
Group=root
ExecStart=/usr/bin/myservice
[Install]
WantedBy=multi-user.target
I am getting some unexpected behavior with this:
The environment variable $HOME is set to /root when I look at the environment variable that myservice is getting which is causing it to fail.
However, as the root user I am getting:
$ echo $HOME
/home/root
This is in line with what I see in /etc/passwd
root:x:0:0:root:/home/root:/bin/sh
When I run myservice manually, it gets the correct $HOME env variable and it works.
I would like $HOME to be /home/root, not /root. So...
- Where is
systemdgetting/rootfrom, and why is$HOMEgetting overwritten? - How do I prevent
systemdfrom doing this globally, aside from explicitly setting the$HOMEenvironment variable in the service file? <-- upon reviewing the source code this doesn't seem like it'll make a difference
/home?systemdhandles cases where root has a non standard home directory