1 |
On Thu, Feb 18, 2016 at 3:57 AM, Duncan <1i5t5.duncan@×××.net> wrote: |
2 |
> Rich Freeman posted on Wed, 17 Feb 2016 08:46:34 -0500 as excerpted: |
3 |
> |
4 |
>> When systemd says "target" - think "virtual service." The equivalent in |
5 |
>> openrc would be an init.d script that has dependencies but which doesn't |
6 |
>> actually launch any processes. |
7 |
>> |
8 |
>> Targets also take the place of runlevels in systemd. |
9 |
> |
10 |
> The systemd official comparison of targets is to runlevels, except much |
11 |
> more flexible as it's actually possible for multiple targets to be in the |
12 |
> process of being reached at once, not services or "virtual services", and |
13 |
> indeed, my immediate internal reaction at seeing the "virtual services" |
14 |
> definition was "no, they're like runlevels", before I even reached the |
15 |
> next paragraph, where you add that. |
16 |
> |
17 |
> Basically, I'd put the runlevel comparison first and primary, as systemd |
18 |
> documentation does, tho now that I've seen the usage, "virtual services" |
19 |
> /does/ add some richness to the definition, helping to accent the fact |
20 |
> that multiple targets can be processed at once. So it's a difference in |
21 |
> emphasis, while agreeing in general. |
22 |
|
23 |
So, perhaps this is getting a bit off-topic, and a bit theoretical. |
24 |
|
25 |
I've found that in general you aren't going to be effective with |
26 |
systemd until you grok some of its basic concepts, and this is one of |
27 |
them. And, frankly, I've never found the "target = runlevel" analogy |
28 |
very helpful when it comes to understanding just what systemd is |
29 |
doing. |
30 |
|
31 |
It is true that systemd uses targets to accomplish what other |
32 |
solutions use runlevels for. However, runlevels are used for things |
33 |
that have nothing to do with traditional runlevels. |
34 |
|
35 |
Here are a few cases where the runlevel analogy fails: |
36 |
|
37 |
1. In most service manager / rc implementations the system is at only |
38 |
one runlevel at any time (of course it might be transitioning between |
39 |
two). In systemd targets can be started independent of the overall |
40 |
"runlevel" and targets that are dependencies of the main runlevel can |
41 |
be reached in parallel at any order semi-independently. |
42 |
|
43 |
2. Targets are used for many intermediate states that most sane rc |
44 |
implementations would never make a separate runlevel, such as gettys |
45 |
running, local filesystems mounted, remote filesystems mounted, |
46 |
network interfaces exist, network is online, name resolution working, |
47 |
swap running, etc. These really don't work like runlevels, and there |
48 |
is no strict sequential order that these get loaded in. |
49 |
|
50 |
3. Targets can be used for convenience just as virtual packages are |
51 |
in most distros. For example, I have an nfs-client target (which just |
52 |
runs whatever daemons are needed to mount remote nfs shares). While |
53 |
upstream doesn't do it this way you could define a samba target that |
54 |
starts both nmbd and smbd. I use targets to group services that get |
55 |
launched together by cron jobs, and so on. |
56 |
|
57 |
4. In the runlevel paradigm you usually think of services running |
58 |
inside a runlevel (perhaps this isn't strictly true, but most people |
59 |
think this way, in part because runlevels don't change much). In |
60 |
systemd this really isn't the case. Services run before targets, or |
61 |
after them. A target won't be considered running if anything it |
62 |
depends on isn't running. |
63 |
|
64 |
5. I'd have to check, but I wouldn't be surprised if systemd doesn't |
65 |
actually require specifying a target at all. Your default "runlevel" |
66 |
could be apache2.service, which means the system would boot and launch |
67 |
everything necessary to get apache working, and it probably wouldn't |
68 |
even spawn a getty. This is NOT analogous to just putting only |
69 |
apache2 in /etc/runlevels/default, because in that example openrc is |
70 |
running the default runlevel, and it only pulls in apache2. Systemd |
71 |
is purely dependency driven and when you tell it to make |
72 |
graphical.target the default runlevel it is like running emerge |
73 |
kde-meta. If all you wanted was kde-runtime you wouldn't redefine |
74 |
kde-meta to pull in only kde-runtime, you'd just run emerge |
75 |
kde-runtime. Again, I haven't tested this, but I'd be shocked if it |
76 |
didn't work. Of course, specifying a service as a default instead of |
77 |
a target is very limiting, but it would probably work. Heck, you |
78 |
could probably specify a mount as the default and the system would |
79 |
just boot and mount something and sit there. Or you could make it a |
80 |
socket and all it would do is sit and listen for a connection |
81 |
inetd-style. |
82 |
|
83 |
|
84 |
I find it more helpful to think of targets as just units that don't do |
85 |
anything. We don't use them in openrc but I suspect it would work out |
86 |
of the box, and maybe we should even consider doing it in at least |
87 |
some cases. For example, right now /etc/init.d/samba uses some |
88 |
scripting to launch both nmbd/smbd and fancy config file parsing to |
89 |
let the users control which ones launch. You could instead break that |
90 |
into three files - smbd, nmbd, and samba. The first two would launch |
91 |
one daemon each, and the samba init.d script wouldn't actually launch |
92 |
anything, but would just depend on the others. That would be the |
93 |
systemd target approach. |
94 |
|
95 |
Apologies if this is a bit off-topic in an openrc discussion, but I |
96 |
think the concept of virtual services is a potentially powerful one, |
97 |
and I think that it might be something openrc would actually benefit |
98 |
from using. |
99 |
|
100 |
However, what I will say is until you actually appreciate that systemd |
101 |
targets are just virtual units then you'll probably find the entire |
102 |
systemd startup process to be an indecipherable mess. Not groking |
103 |
this stuff also makes it easy to incorrectly specify dependencies. |
104 |
I'm sure a few of us running openrc over the years have accidentially |
105 |
stuck a service in the wrong runlevel and had something break. Well, |
106 |
in systemd you might have 47 "runlevels" not actually starting in any |
107 |
particular order so it is much easier to get it wrong if you don't |
108 |
realize how they work. They aren't strictly sequential, so there |
109 |
isn't always one "runlevel" that always comes last that you can be |
110 |
lazy and stick something "in." |
111 |
|
112 |
|
113 |
-- |
114 |
Rich |