[systemd-devel] systemctl preset for user units (and how presets are applied after factory reset)

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Mon Oct 27 06:52:39 PDT 2014


On Mon, Oct 27, 2014 at 10:42:56AM +0000, Colin Guthrie wrote:
> So that led me to ask myself: does systemctl preset support user units?
> The man page doesn't make it clear that e.g. the --global switch applies
> to preset as well as enable, but in testing it (happily) appears to
> work! So I'm going to answer that question with a "yes, it does work!"
SYNOPSIS lists a few .../user-preset/... paths, which indicates that
it does.

> So, as preset works for user-units, I'm thinking that we should NOT ship
> a /usr/lib/systemd/user/socket.target.wants/pulseaudio.socket symlink
> and leave it to downstream packagers to call "systemctl preset --global
> pulseaudio.socket" when the package is first installed. This will create
> the /etc/systemd/user/socket.target.wants/pulseaudio.socket symlink for
> us and all is well.
> 
> [As a side note, if this is the recommended approach, then we should
> probably add appropriate RPM macros to macros.systemd for user unit
> presets...]
Good point.

> There are, however, two questions still remain:
> 
> 1. As we have two units, pulseaudio.socket and pulseaudio.service, and
> as the desired behaviour is to enable only the socket but not the
> service (i.e. by default rely on socket activation - don't waste
> resources unless a client actually connects; this is a bit of an
> assumption - perhaps this should be desirable?) should we:
>   a) Recommend packagers only call "systemctl preset --global
> pulseaudio.socket"
>   b) Recommend packagers call "systemctl preset --global
> pulseaudio.socket pulseaudio.service", but remove the [Install] section
> from the .service
>   c) Recommend packagers call "systemctl preset --global
> pulseaudio.socket pulseaudio.service", but ship a preset file in
> /usr/lib/systemd/user-preset/50-pulseaudio.preset that has "disable
> pulseaudio.service" in it.

Neither of those. Distribution packaging should set the default
policy, which in case of Fedora would be 'disable *', and
the package specific policy, containing just 'enable pulseaudio.socket'
assuming that only socket activiation is desired.

This way, full flexibility is retained, and distributions like
Fedora that don't activate by default on package installation, and
the ones like Debian that sometimes do, attain desired behaviour
by simply chaning one or two lines in the presets files.

> systemd.preset(5) suggests not to do c) but I think this could be an
> example of an exception to that rule (to me this seems cleanest)?
> Perhaps there are other socket+service pairs where this makes sense too
> however, and this should be encapsulated in the preset logic more
> generally? (i.e. the default logic is "if a .service unit is set to be
> enabled, double check to see if it has a corresponding .socket unit
> which will be enabled and if so, skip enabling the .service".
> 
> 2. On factory reset, I do not see any calls to systemctl preset, for
> either the system or user units. Am I missing something or is this
> something which should be part of the factory reset logic (i.e. a unit
> with ConditionNeedsUpdate=/etc to call systemctl preset - if so, it
> would presumably also need to reload systemd if any work was done for
> system units, but we can assume this is safely completed before any user
> instances kick in).
I seems this should be done. I thought that factory-reset already does
that...

Zbyszek


More information about the systemd-devel mailing list