[systemd-devel] Standardizing names for graphical session units -- version 3, now working!

Martin Pitt martin.pitt at ubuntu.com
Wed Jul 6 13:18:18 UTC 2016


Andrei Borzenkov [2016-07-06 14:44 +0300]:
> On Wed, Jul 6, 2016 at 2:25 PM, Martin Pitt <martin.pitt at ubuntu.com> wrote:
> >    $ cat .config/systemd/user/gnome-session.target
> >    [Unit]
> >    Description=User systemd services for GNOME graphical session
> >    Requires=graphical.target
> >    PartOf=graphical.target
> >
> 
> Is not this redundant? Requires=graphical.target already stops
> gnome-session.target when graphical.target is stopped (by any mean).

Yes, but at the same time Requires= isn't strong enough, it needs
BindsTo=.

> > The only glitch is that "systemctl --user stop gnome-session.target"
> > only stops that target itself. I would have expected it to stop
> > graphical.target too (and someapp along with it), as it has
> > PartOf=graphical.target. This might be a bug in systemd, or some
> > semantics of PartOf with targets that I don't understand.
> 
> You probably do not understand. If foo.service is PartOf=bar.target,
> then stopping bar.target stops foo.service. State of foo.service
> itself has no impact of bar.target.

Indeed, thanks. This needs another BindsTo=.

I now created a script which sets up the units and exercises various
start/stop scenarios to ensure that we get the behaviour that we want.
This now introduces a (fake) gnome-session.service that we consider
the "session leader", and renames gnome-session.target to just
gnome.target to make it less likely to be mixed up with
gnome-session.service:

  http://people.canonical.com/~pitti/tmp/session.sh

This makes it much easier to mess around with the units and check that
stuff still works. This is now as simple as I could get it without
breaking the desired behaviour:

 * Starting gnome.target starts gnome-session.service,
   someapp.service, and graphical.target.

 * Stopping gnome.target OR graphical.target stops the services.

 * Stopping or killing gnome-session.target stops everything else.

 * someapp.service starts along with the session but can be
   stopped/restarted independently.

So we still have the requirement of an abstract "graphical.target"
that particular session services can be PartOf=, so that we avoid
having to change every service whenever a new session type arrives.

This works on systemd 230 as-is, without the need to change anything.

Note that this writes units into ~/.config/systemd/user, so if you run
this you need to clean up that dir afterwards.

Thanks,

Martin
-- 
Martin Pitt                        | http://www.piware.de
Ubuntu Developer (www.ubuntu.com)  | Debian Developer  (www.debian.org)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20160706/5d21576d/attachment.sig>


More information about the systemd-devel mailing list