Gentoo Archives: gentoo-dev

From: Andrew Savchenko <bircoph@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] rfc: openrc service script dependency checker
Date: Thu, 04 Dec 2014 12:54:22
Message-Id: 20141204155403.1e388a5c04839e2fefe75abe@gentoo.org
In Reply to: [gentoo-dev] rfc: openrc service script dependency checker by William Hubbs
1 Hello,
2
3 On Wed, 3 Dec 2014 12:39:12 -0600 William Hubbs wrote:
4 > All,
5 >
6 > we have a pull request on OpenRC for a dependency checker [1].
7 >
8 > The author of this patch believes that we should not only scan for
9 > circular deps, but break some of them automatically.
10
11 Situation is more complicated than that. There are two loop
12 solvers, see below.
13
14 > I, and several other team members I have spoken with on IRC, disagree
15 > with this and think that we should just warn about the circular deps
16 > since users can break them by modifying files in /etc/conf.d, and the
17 > service script writers should be told about these kinds of issues so
18 > they can determine whether they neeed to adjust the dependencies in
19 > their scripts.
20 >
21 > I wanted to post a question here to see what people think, so feel free
22 > to comment.
23 >
24 > My opinion is the less automatic adjustment we do the better.
25
26 Short opinion for those not interested in reading a long text below.
27
28 1. Warn users about loops.
29 2. Break loops.
30 3. Make both options above configurable (on/off).
31 Gentoo is all about choise, right?
32
33 Now the long story follows.
34
35 Why do loops occur? This depends on distribution being used. While
36 in Gentoo loops in deps are usually errors, in Debian loops are
37 unavoidable and must be handled, otherwise they will never accept
38 OpenRC as an alternative to systemd and other init systems.
39
40 Why there are loops in Debian? Here are few cases (though full list
41 of reasons is not limited to these cases):
42
43 1. There are multiple services having "after $all" statement (an
44 analog in Gentoo is "after *", which is currently used only by
45 local init.d script).
46
47 2. LSB dependencies are allowed to be asymmetrical relative to start
48 and stop, while in OpenRC they are symmetrical. This yields to
49 loops in OpenRC while in LSB the same services work fine. Example
50 follows:
51
52 cryptdisks <-a umountfs <-u hwclock.sh <-a checkroot <-n cryptdisks
53 where X <-a Y means Y after X;
54 X <-u Y is for Y uses X; and
55 X <-n Y is for Y needs X.
56
57 Actually cryptdisks needs checkroot only on start and hwclock.sh
58 uses umountfs only on stop (shutdown), so there are no issues for
59 LSB, but OpenRC have a loop here, which can be broken between
60 umountfs <-u hwclocs, because "use" is the weakest type of
61 dependecy.
62
63 While it was suggested on #openrc IRC channel that Debian may switch
64 to runscript-format dependencies, this may be possible only in
65 distant future (and I doubt even this) and this step is not
66 acceptable right now. So it is a statement of fact that OpenRC
67 should be compatible with LSB dependencies. Probably zigo and
68 heroxbd may give you more insight on this issue.
69
70 Warnings for users about loops is a good idea for Gentoo, but will
71 produce a lot of not always wanted output on Debian, that's why
72 this option should be configurable.
73
74 As for loop breaker, its presence depends on setup and user needs.
75 It is definitely needed in Debian for the reasons described above.
76
77 As for Gentoo it is desirable too, becase it is better to boot
78 system somehow instead of not booting it at all (or with long
79 delays due to 60-seconds timeout on service startup). This is
80 crucial for remote servers, e.g. admin needs to reboot machine due
81 to critical security kernel update ASAP and having it hang during
82 boot is really a very bad idea. Another example from my experience
83 is emergency shutdown due to power failure and low battery signal
84 from sys-power/nut. I had several nasty cases when system failed to
85 shutdown properly due to 60-second timeouts for services failed to
86 shutdown — battery just ran out of charge while OpenRC was try to
87 do thing "right way".
88
89 Of course you mileage may vary, that's why loop breaker option
90 should be configurable.
91
92 But I see of no reason why we have right to force users to do what
93 we believe is right, instead of letting them choose what they need
94 based on their profile, preferences, setups, workflow and so on.
95
96 For those interested in more details:
97
98 There are two loop solvers. The first one, early-loop-solver which
99 is currently discussed:
100 https://github.com/openrc/openrc/pull/12
101 https://github.com/xaionaro/openrc/tree/earlyloopdetector
102
103 It solves all loops where there is at least one weak dependency
104 ("after" or "use"). And this is done during dependency cache
105 generation process, so there is no run-time penalty for system
106 startup or shutdown.
107
108 But if one have a "hard" dependency where all graph edges are
109 "need", e.g.:
110 A <-need B <-need C <-need A
111 then there is no way to break this dependency during cache
112 generation and it should be broken on run-time, that's why
113 later-loop-detector exists:
114 https://github.com/xaionaro/openrc/tree/laterloopdetector
115 And it does its dirty job :)
116
117 If someone is enterested in loop detection and solver algorithms,
118 there are well described in the following presentation:
119 https://github.com/xaionaro/documentation/blob/master/openrc/earlyloopdetector/early-loop-detection.pdf
120
121 I tested both loop detectors on several Gentoo hosts for about 9
122 months now and they work fine for me. In Debian people also tested
123 them for a while and one bug was found and fixed since then.
124
125 Best regards,
126 Andrew Savchenko

Replies

Subject Author
Re: [gentoo-dev] rfc: openrc service script dependency checker Rich Freeman <rich0@g.o>