There are programs that I want to automatically start after a successful graphical desktop login (e.g. to Gnome or Xmonad) and stop when I logout. How can I change the ~/.config/systemd/user/synergys.service file to do the above properly?
Right now with the service enabled, according to journalctl --user, the service tries to start when I login but fails with
Invalid MIT-MAGIC-COOKIE-1...
which I think basically means it failed to get a display. When I manually start it after logging in, it's fine. I suspect the service is starting too early, before there's a display, because WantedBy=default.target is not specific to a GUI login and even a text login will trigger it.
I've experimented with graphical-session.target but that went nowhere. This is on Ubuntu 20.04.
[Unit]
Description=Synergy Server
[Service]
ExecStart=/usr/bin/synergys --no-daemon --no-tray --address :: --serial-key XXXX --enable-crypto
Restart=always
RestartSec=3
[Install]
WantedBy=default.target
I know I can manually run the program as a desktop session 'startup' program, but this way does not provide automatic retry upon failure.
graphical-session.target? Was itPartOf=graphical-session.target? How did it fail?PartOf=graphical-session.targetunder[Unit]and removed[Install]. This worked for a Gnome login session but not for an xmonad login session, where the service did not start.systemctl --user list-units --type targetshows a graphical-session.target under Gnome but not under xmonad. I'm looking for a way that works for different types of sessions and I don't know how graphical-session.target works. These sessions are started from lightdm.