Gentoo Archives: gentoo-amd64

From: Marc Joliet <marcec@×××.de>
To: gentoo-amd64@l.g.o
Subject: Re: [gentoo-amd64] Systemd migration: opinion and questions
Date: Tue, 24 Feb 2015 23:11:29
Message-Id: 20150225001118.339f59da@marcec.fritz.box
In Reply to: Re: [gentoo-amd64] Systemd migration: opinion and questions by Randy Barlow
1 Am Tue, 24 Feb 2015 15:41:51 -0500
2 schrieb Randy Barlow <randy@×××××××××××××××××.com>:
3
4 > -----BEGIN PGP SIGNED MESSAGE-----
5 > Hash: SHA1
6 >
7 > On 02/24/2015 03:15 PM, Marc Joliet wrote:
8 > > === User units ===
9 > >
10 > > I would like to convert some programs I start in .xprofile to units
11 > > that are started by my users's systemd instance. I started off
12 > > with mpd, but it doesn't start automatically ("systemctl --user
13 > > start mpd" works fine, though), even though it's enabled:
14 > >
15 > > % systemctl --user status mpd ● mpd.service - Music Player Daemon
16 > > Loaded: loaded (/usr/lib64/systemd/system/mpd.service; enabled)
17 > > Active: active (running) since Di 2015-02-24 19:39:46 CET; 1h 6min
18 > > ago Main PID: 1091 (mpd) CGroup:
19 > > /user.slice/user-1000.slice/user@××××.service/mpd.service └─1091
20 > > /usr/bin/mpd --no-daemon
21 > >
22 > > Feb 24 19:39:46 marcec systemd[384]: Started Music Player Daemon.
23 > > [...]
24 > >
25 > > Also:
26 > >
27 > > % tree .config/systemd/ .config/systemd/ └── user ├── mpd.service
28 > > -> /usr/lib64/systemd/system/mpd.service └──
29 > > multi-user.target.wants └── mpd.service ->
30 > > /home/marcec/.config/systemd/user/mpd.service
31 > >
32 > > Is the symlink the problem? Do I have to create an actual file?
33 > > Is the target.wants wrong?
34 >
35 > I ran into this problem as well. It is indeed the symlink! There is an
36 > RFE filed for this:
37 >
38 > https://bugzilla.redhat.com/show_bug.cgi?id=1014311
39
40 Hmm, I don't think that's related. It's not that the service isn't enabled, it
41 doesn't start automatically.
42
43 However, after looking at the Arch wiki again
44 (https://wiki.archlinux.org/index.php/Systemd/User#How_it_works), I found the
45 key bit of info I needed:
46
47 "When systemd user instance starts, it brings up the target default.target."
48
49 So I need to add a symlink to *default*.target.wants/, then MPD starts when I
50 log in! So I ended up with this trivial user unit, which replaced the symlink
51 I had their experimentally:
52
53 % cat .config/systemd/user/mpd.service
54 .include /usr/lib/systemd/system/mpd.service
55
56 [Install]
57 WantedBy=default.target
58
59 What was more difficult was getting it to depend on the right network target
60 properly. The same "Requires" line that worked for samba and cups fails with
61 "failed to add dependency" type errors:
62
63 Feb 24 21:20:01 marcec systemd[540]: Cannot add dependency job for unit
64 mpd.service, ignoring: Unit netctl@×××××××××.service failed to load: No such file or directory.
65
66 So apparently user units can't "Require" system units? However, adding a
67 symlink from the service unit in /etc to .../mpd.service.requires/ solved that
68 problem, but yielded a new one:
69
70 Feb 24 23:26:49 marcec network[2200]: netctl needs root privileges
71
72 Oh, well... Maybe it would work with systemd-networkd?
73
74 Regardless,, I solved that by changing my MPD configuration to bind to
75 "any" (equivalent to 0.0.0.0), since it was trying to bind to all interfaces
76 individually anyway. So I dropped the Requires, and everything is fine now.
77
78 But now I need to see what else might profit from being started this way :) .
79
80 > You don't have to create the entire file either though, it turns out.
81 > It is possible to inherit a unit in a unit, so you could create a unit
82 > that just inherits the one from /usr/lib. I've never tried this with a
83 > user unit, but I suspect it would work. Read the section "Example 2.
84 > Overriding vendor settings" at the end of this page:
85 >
86 > http://www.freedesktop.org/software/systemd/man/systemd.unit.html
87
88 Thanks, I do in fact know about that, but I can still use reminders now and
89 again :-) .
90
91 --
92 Marc Joliet
93 --
94 "People who think they know everything really annoy those of us who know we
95 don't" - Bjarne Stroustrup

Replies

Subject Author
Re: [gentoo-amd64] Systemd migration: opinion and questions Marc Joliet <marcec@×××.de>