systemd services can be configured at the user account level (without root privileges). The services should be stored in the directory ${HOME}/.config/systemd/user
.
First make sure the directory to store the service file exists:
mkdir -p ${HOME}/.config/systemd/user
Create the service file, eg. ${HOME}/.config/systemd/user/myservice.service
. In this case, the service will execute the command /opt/myservice
.
[Unit]
Description=My custom user level service
[Service]
Restart=always
ExecStart=/opt/myservice
[Install]
WantedBy=multi-user.target
The service can then be enabled and started:
systemctl --user enable myservice.service
systemctl --user start myservice.service
Process lingering must be enabled if the user will not be logged in and the service is required to still run. To enable process lingering:
sudo loginctl enable-linger $USER