Gentoo Archives: gentoo-dev

From: Wout Mertens <wmertens@g.o>
To: Martin Schlemmer <azarah@g.o>
Cc: Wolfram Schlich <lists@×××××××.org>, Gentoo-Dev mailinglist <gentoo-dev@g.o>
Subject: Re: [gentoo-dev] rc-scripts/init: new service dependency
Date: Tue, 06 May 2003 23:56:42
Message-Id: Pine.GSO.4.53.0305070147220.6252@bru-cse-075.cisco.com
In Reply to: Re: [gentoo-dev] rc-scripts/init: new service dependency by Martin Schlemmer
1 On Tue, 6 May 2003, Martin Schlemmer wrote:
2
3 > On Tue, 2003-05-06 at 21:59, Wout Mertens wrote:
4 >
5 > > That's what I meant: when the service is called for an action (start,
6 > > stop, restart, reload, custom things), runscript will run the event()
7 > > function for all the scripts that are subscribed to that script, and then
8 > > those scripts can figure out what to do with it themselves...
9 > >
10 > > And the gentoo-net scripts that I am working on will go down a
11 > > user-configurable list when certain things happen. (interface up/down, ip
12 > > address changed, etc.
13 > >
14 > > The design pattern we're looking at here is events and interested parties,
15 > > and it's just a matter of defining what events we handle and how we notify
16 > > the parties.
17 > >
18 >
19 > So in the network context:
20 >
21 > -------- add to /etc/conf.d/net ---------
22 > modules_eth0="static route firewall"
23 > -----------------------------------------
24 >
25 > -------- add to /etc/init.d/net.eth? ----
26 > depend() {
27 > subscribe after ${modules_eth0}
28 > }
29 > -----------------------------------------
30 >
31 > and if net.eth0 starts (meaning the interface is present for example),
32 > it will run the 'static' module to set the static ip, then do the
33 > routes, and lastly add firewall/whatever rules. Same in reverse if
34 > its stopped.
35
36 Actually, his is what I want to implement in gentoo-net, but it isn't what
37 I described :)
38
39 I described the reverse:
40
41 In your example, interpreted by what I meant, if you start
42 /etc/init.d/static, it will, after running the start function in
43 /etc/init.d/static, run the event function in /etc/init.d/net.eth?, with
44 arguments "static" "start" "after".
45
46 So the net.eth? script gets notified about the static script being
47 started, without the static script having to do anything.
48
49 And it calls the event() function because you don't necessarily want to
50 start the service when another one started, so that way you can choose
51 what you do.
52
53 > Note that above might be too simplified, and out of context.
54 >
55 > This brings up a question or two:
56 >
57 > 1) should this work for all rc-scripts, or should we maybe
58 > add a /etc/init.d/modules/ that have very job specific
59 > scripts that are related to net.* (net.eth?, net.ppp?, net.foo)
60 > 2) if yes to 1), will we need it for anything else than net.* stuff ?
61
62 Very generally speaking, we want to be able to run scripts when some
63 device or service changes state. In gentoo-net, that is the network
64 interface device and the IP "device" (e.g. when the IP address changes you
65 want to update your dynamic dns entry).
66
67 But what about hotplugged devices? Cardbus, usb, pci? These, too, are
68 interesting to run scripts against, for instance to automatically mount a
69 usb storage device.
70
71 Right now, Mandrake has something in place that handles some hotplugging
72 events, but networks aren't handled. In 2.6, the kernel will have a more
73 generic devices tree (sysfs), which might or might not consider bringing a
74 network device up a hotplug event, easy to handle in a generic way.
75
76 So what I'm saying is that it could be useful to set up a generic
77 framework that handles all these things, and reroute the packages that do
78 their own thing to use that interface: hotplug, pcmcia_cs, dhcpcd, ppp and
79 so on all have hooks that can be executed when something happens, and they
80 could thus be written to send an event instead of doing something.
81
82 So what I would like to see is that you can subscribe to generic
83 user-definable events, and that triggering an event will cause all the
84 subscribed initscripts to be notified.
85
86 > 3) you mentioned a few events ... do we really need them all, or could
87 > we get away with a 'start/stop' only ?
88
89 I think that the overhead required to implement start/stop is roughly the
90 same as doing it for a number of events, so I wouldn't want us to cut
91 ourselves short...
92
93 > To get it running, is not the issue. The bigger issue is getting it
94 > functional, without too much bloat/speed decrease/complexity, with
95 > a stable API that do not have to change every few months. Basically
96 > we will need to think what exactly is needed, and will be needed.
97
98 Here's two possibilities for doing things after a network interface came
99 up:
100
101 1) semi-hardcoded:
102 - put a bunch of SysV init style symlinks to initscripts in
103 /etc/conf.d/net.d/ifup.d/
104 - the interface comes up
105 - start/stop each of them in order, with $INTERFACE set to the interface,
106
107 Pro: Easy to write, the user has full control over what gets started or
108 stopped
109
110 Con: hard to maintain the SysV init style directory, each event needs a
111 directory, solves only one problem.
112
113 2) event based:
114 - the initscripts put subscribe statements in their depend() code
115 - the interface comes up
116 - the event dispatcher runs the subscribed initscripts event() functions,
117 with details about the event (who, what and args).
118
119 Pro: Easy to write the initscripts, solves many problems. The event
120 dispatcher shouldn't be difficult.
121
122 Con: Need to find a nice way for a user to disable an initscript, so it
123 doesn't get events. Example: the net may be up, but the user doesn't want
124 wwwoffle to be brought online.
125
126 Thoughts?
127
128 Wout.
129
130 --
131 gentoo-dev@g.o mailing list

Replies