Here is what I just created as workaround to the not yet available graphical-session.target (On my Kubuntu 16.04 system):
- Create a pseudo systemd user unit which brings the graphical-session.target up and down.
Create ~/.config/systemd/user/xsession.target with following contents:
[Unit]
Description = Xsession up and running
BindsTo=graphical-session.target
Tell systemd about this new unit:
$> systemctl --user daemon-reload
- Create autostart and shutdown scripts which controls the
xsession.target via the currently available mechanics of the Ubuntu 16.04 desktop.
Create ~/.config/autostart-scripts/xsession.target-login.sh with following contents:
#!/bin/bash
if ! systemctl --user is-active xsession.target &> /dev/null
then
/bin/systemctl --user import-environment DISPLAY XAUTHORITY
/bin/systemctl --user start xsession.target
fi
Create ~/.config/plasma-workspace/shutdown/xsession.target-logout.sh with following contents:
#!/bin/bash
if systemctl --user is-active xsession.target &> /dev/null
then
/bin/systemctl --user stop xsession.target
fi
Make the scripts executable:
$> chmod +x ~/.config/autostart-scripts/xsession.target-login.sh
$> chmod +x ~/.config/plasma-workspace/shutdown/xsession.target-logout.sh
Note: these two files are placed where KDE will pick them up for autostart and shutdown. The files maybe placed somewhere else for other desktop environments (e.g. Gnome) - but I don't know about those environments.
Note: This workaround lacks support of multi desktop sessions. It only handles the graphical-session.target correctly as long as only one active X11 session is run on a machine (but that's the case for most of us linux users).
- Create your own systemd user units which depend on
graphical-session.target and have them run cleanly while being logged in on your desktop.
As example @mkaito's unit should look like this:
[Unit]
Description=Redshift
PartOf=graphical-session.target
[Service]
ExecStart=/bin/redshift -l 28:-13 -t 5300:3300 -b 0.80:0.91 -m randr
Restart=always
(Don't forget to do a daemon-reload after editing your units!)
- Reboot your machine, login and verfiy your units are started as expected
$> systemctl --user status graphical-session.target
● graphical-session.target - Current graphical user session
Loaded: loaded (/usr/lib/systemd/user/graphical-session.target; static; vendor preset: enabled)
Active: active since Don 2017-01-05 15:08:42 CET; 47min ago
Docs: man:systemd.special(7)
$> systemctl --user status your-unit...
At some future day (will it be Ubuntu 17.04?) my workaround become obsolete since the system will handle the graphical-session.target correctly itself.
At that day just remove the autostart and shutdown script and also the xsession.target - your custom user units may stay untouched and just work.