Re: Systemd migration: opinion and questions

Marc Joliet <[email protected]> Wed, 25 Feb 2015 00:11:18 +0100
Newsgroups gmane.linux.gentoo.amd64
Message-ID <[email protected]>
Am Tue, 24 Feb 2015 15:41:51 -0500
schrieb Randy Barlow <[email protected]>:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On 02/24/2015 03:15 PM, Marc Joliet wrote:
> > === User units ===
> > 
> > I would like to convert some programs I start in .xprofile to units
> > that are started by my users's systemd instance.  I started off
> > with mpd, but it doesn't start automatically ("systemctl --user
> > start mpd" works fine, though), even though it's enabled:
> > 
> > % systemctl --user status mpd ● mpd.service - Music Player Daemon 
> > Loaded: loaded (/usr/lib64/systemd/system/mpd.service; enabled) 
> > Active: active (running) since Di 2015-02-24 19:39:46 CET; 1h 6min
> > ago Main PID: 1091 (mpd) CGroup:
> > /user.slice/user-1000.slice/[email protected]/mpd.service └─1091
> > /usr/bin/mpd --no-daemon
> > 
> > Feb 24 19:39:46 marcec systemd[384]: Started Music Player Daemon. 
> > [...]
> > 
> > Also:
> > 
> > % tree .config/systemd/ .config/systemd/ └── user ├── mpd.service
> > -> /usr/lib64/systemd/system/mpd.service └──
> > multi-user.target.wants └── mpd.service ->
> > /home/marcec/.config/systemd/user/mpd.service
> > 
> > Is the symlink the problem?  Do I have to create an actual file?
> > Is the target.wants wrong?
> 
> I ran into this problem as well. It is indeed the symlink! There is an
> RFE filed for this:
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1014311

Hmm, I don't think that's related.  It's not that the service isn't enabled, it
doesn't start automatically.

However, after looking at the Arch wiki again
(https://wiki.archlinux.org/index.php/Systemd/User#How_it_works), I found the
key bit of info I needed:

    "When systemd user instance starts, it brings up the target default.target."

So I need to add a symlink to *default*.target.wants/, then MPD starts when I
log in!  So I ended up with this trivial user unit, which replaced the symlink
I had their experimentally:

    % cat .config/systemd/user/mpd.service
    .include /usr/lib/systemd/system/mpd.service

    [Install]
    WantedBy=default.target

What was more difficult was getting it to depend on the right network target
properly.  The same "Requires" line that worked for samba and cups fails with
"failed to add dependency" type errors:

    Feb 24 21:20:01 marcec systemd[540]: Cannot add dependency job for unit
    mpd.service, ignoring: Unit [email protected] failed to load: No such file or directory.

So apparently user units can't "Require" system units? However, adding a
symlink from the service unit in /etc to .../mpd.service.requires/ solved that
problem, but yielded a new one:

    Feb 24 23:26:49 marcec network[2200]: netctl needs root privileges

Oh, well... Maybe it would work with systemd-networkd?

Regardless,, I solved that by changing my MPD configuration to bind to
"any" (equivalent to 0.0.0.0), since it was trying to bind to all interfaces
individually anyway.  So I dropped the Requires, and everything is fine now.

But now I need to see what else might profit from being started this way :) .

> You don't have to create the entire file either though, it turns out.
> It is possible to inherit a unit in a unit, so you could create a unit
> that just inherits the one from /usr/lib. I've never tried this with a
> user unit, but I suspect it would work. Read the section "Example 2.
> Overriding vendor settings" at the end of this page:
> 
> http://www.freedesktop.org/software/systemd/man/systemd.unit.html

Thanks, I do in fact know about that, but I can still use reminders now and
again :-) .

-- 
Marc Joliet