I have a script that is running as root and am trying to have it setup a user service to run an IPFS daemon. The problem is that I need to enable the service as the user rather than as root. It usually works after a restart but I'd like to avoid that if I can.
The service script is located at ~/.config/systemd/user/ipfs.service
It contains:
[Unit]
Description=IPFS daemon
[Service]
# Environment="IPFS_PATH=/data/ipfs" # optional path to ipfs init directory if not default (\$HOME/.ipfs)
ExecStart=/usr/local/bin/ipfs daemon
Restart=on-failure
[Install]
WantedBy=default.target
(I took this code from here: https://github.com/ipfs/go-ipfs/tree/master/misc )
If I run these command as the user it works correctly:
systemctl --user enable ipfs
systemctl --user start ipfs
The problem is that my script is running as root, and I can't figure out how to get this to run as the user. I have tried this so far:
# Enable linger so IPFS can run at boot
loginctl enable-linger $USER_ACCOUNT
# Enable the service to run at boot
sudo -u $USER_ACCOUNT systemctl --user enable ipfs
# Start the service now
sudo -u $USER_ACCOUNT systemctl --user start ipfs
Unfortunately with this the service does not start and when I get this error message:
Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined (consider using [email protected] --user to connect to bus of other user)
Once the script has finished, and I reboot, the service starts fine but I would like to avoid the user having to reboot if I can. Any help would be appreciated.