I am trying to setup a service which requires access to X-Windows and DBus. First I tried it as a background application, but that just doesn't work. I use the "auto-log user" feature. Now I think that the service needs to run as that auto-log user (say alexis). My problem is that I can easily create a service running as that user (i.e. setting the User=alexis and Group=alexis variables). I also had to add an environment variable (DISPLAY=:0). However, the service is still started as a system service.
What I was thinking is to create a service in a way that it get started when the user logs in. I see many systemd entries when I run:
systemctl --user list-units
but I'm not too sure how to create such a service file and get the Ubuntu package creation tool chain to create a service which is for users and not the OS at large.
The following is my current my-daemon.service file which lingers in the debian folder of the project:
# Documentation available at:
# https://www.freedesktop.org/software/systemd/man/systemd.service.html
[Unit]
Description=Daemon
[Service]
Type=simple
WorkingDirectory=~
ProtectHome=false
NoNewPrivileges=true
ExecStart=/usr/sbin/my-daemon
ExecStop=kill "$MAINPID"
Restart=on-failure
RestartSec=1min
User=alexis
Group=alexis
LimitNPROC=1000
[Install]
WantedBy=xsession.target
So the service file gets installed under /lib/systemd/system and I think that's wrong in my situation. Otherwise it looks like it works as expected... but I'm not really 100% sure the settings are correct for a per-user unit. I've been looking around and I was not able to find much about user units. It's like something that must be top secret...