Gentoo Archives: gentoo-commits

From: William Hubbs <williamh@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/openrc:master commit in: /
Date: Wed, 10 Jan 2018 19:30:02
Message-Id: 1515612313.14e3359a9e4174da3e422957d9de56907f025875.williamh@OpenRC
1 commit: 14e3359a9e4174da3e422957d9de56907f025875
2 Author: William Hubbs <w.d.hubbs <AT> gmail <DOT> com>
3 AuthorDate: Wed Jan 10 19:25:13 2018 +0000
4 Commit: William Hubbs <williamh <AT> gentoo <DOT> org>
5 CommitDate: Wed Jan 10 19:25:13 2018 +0000
6 URL: https://gitweb.gentoo.org/proj/openrc.git/commit/?id=14e3359a
7
8 move developer documentation from guide.md to service-script-guide.md
9
10 guide.md | 125 ++++--------------------------------------------
11 service-script-guide.md | 109 +++++++++++++++++++++++++++++++++++++++++
12 2 files changed, 117 insertions(+), 117 deletions(-)
13
14 diff --git a/guide.md b/guide.md
15 index f8c23194..80c8a7d3 100644
16 --- a/guide.md
17 +++ b/guide.md
18 @@ -27,8 +27,8 @@ openrc scans the runlevels (default: `/etc/runlevels`) and builds a dependency
19 graph, then starts the needed service scripts, either serialized (default) or in
20 parallel.
21
22 -When all the init scripts are started openrc terminates. There is no persistent
23 -daemon. (Integration with tools like monit, runit or s6 can be done)
24 +When all the service scripts are started openrc terminates. There is no
25 +persistent daemon. (Integration with tools like monit, runit or s6 can be done)
26
27 # Shutdown
28
29 @@ -63,7 +63,7 @@ own if needed. This allows, for example, to have a default runlevel with
30 disabled.
31
32 The `rc-status` helper will print all currently active runlevels and the state
33 -of init scripts in them:
34 +of services in them:
35
36 ```
37 # rc-status
38 @@ -74,7 +74,7 @@ Runlevel: default
39 ```
40
41 All runlevels are represented as folders in `/etc/runlevels/` with symlinks to
42 -the actual init scripts.
43 +the actual service scripts.
44
45 Calling openrc with an argument (`openrc default`) will switch to that
46 runlevel; this will start and stop services as needed.
47 @@ -83,122 +83,13 @@ Managing runlevels is usually done through the `rc-update` helper, but could of
48 course be done by hand if desired.
49 e.g. `rc-update add nginx default` - add nginx to the default runlevel
50 Note: This will not auto-start nginx! You'd still have to trigger `rc` or run
51 -the initscript by hand.
52 +the service script by hand.
53
54 FIXME: Document stacked runlevels
55
56 The default startup uses the runlevels `boot`, `sysinit` and `default`, in that
57 order. Shutdown uses the `shutdown` runlevel.
58
59 -
60 -# Syntax of Service Scripts
61 -
62 -Service scripts are shell scripts. OpenRC aims at using only the standardized
63 -POSIX sh subset for portability reasons. The default interpreter (build-time
64 -toggle) is `/bin/sh`, so using for example mksh is not a problem.
65 -
66 -OpenRC has been tested with busybox sh, ash, dash, bash, mksh, zsh and possibly
67 -others. Using busybox sh has been difficult as it replaces commands with
68 -builtins that don't offer the expected features.
69 -
70 -The interpreter for initscripts is `#!/sbin/openrc-run`.
71 -Not using this interpreter will break the use of dependencies and is not
72 -supported. (iow: if you insist on using `#!/bin/sh` you're on your own)
73 -
74 -A `depend` function declares the dependencies of this service script.
75 -All scripts must have start/stop/status functions, but defaults are provided.
76 -Extra functions can be added easily:
77 -
78 -```
79 -extra_commands="checkconfig"
80 -checkconfig() {
81 - doSomething
82 -}
83 -```
84 -
85 -This exports the checkconfig function so that `/etc/init.d/someservice
86 -checkconfig` will be available, and it "just" runs this function.
87 -
88 -While commands defined in `extra_commands` are always available, commands
89 -defined in `extra_started_commands` will only work when the service is started
90 -and those defined in `extra_stopped_commands` will only work when the service is
91 -stopped. This can be used for implementing graceful reload and similar
92 -behaviour.
93 -
94 -Adding a restart function will not work, this is a design decision within
95 -OpenRC. Since there may be dependencies involved (e.g. network -> apache) a
96 -restart function is in general not going to work.
97 -restart is internally mapped to `stop()` + `start()` (plus handling dependencies).
98 -If a service needs to behave differently when it is being restarted vs
99 -started or stopped, it should test the `$RC_CMD` variable, for example:
100 -
101 -```
102 -[ "$RC_CMD" = restart ] && do_something
103 -```
104 -
105 -# The Depend Function
106 -
107 -This function declares the dependencies for a service script. This
108 -determines the order the service scripts start.
109 -
110 -```
111 -depend() {
112 - need net
113 - use dns logger netmount
114 - want coolservice
115 -}
116 -```
117 -
118 -`need` declares a hard dependency - net always needs to be started before this
119 - service does
120 -
121 -`use` is a soft dependency - if dns, logger or netmount is in this runlevel
122 - start it before, but we don't care if it's not in this runlevel.
123 - `want` is between need and use - try to start coolservice if it is
124 - installed on the system, regardless of whether it is in the
125 - runlevel, but we don't care if it starts.
126 -
127 -`before` declares that we need to be started before another service
128 -
129 -`after` declares that we need to be started after another service, without
130 - creating a dependency (so on calling stop the two are independent)
131 -
132 -`provide` allows multiple implementations to provide one service type, e.g.:
133 - `provide cron` is set in all cron-daemons, so any one of them started
134 - satisfies a cron dependency
135 -
136 -`keyword` allows platform-specific overrides, e.g. `keyword -lxc` makes this
137 - service script a noop in lxc containers. Useful for things like keymaps,
138 - module loading etc. that are either platform-specific or not available
139 - in containers/virtualization/...
140 -
141 -FIXME: Anything missing in this list?
142 -
143 -# The Default Functions
144 -
145 -All service scripts are assumed to have the following functions:
146 -
147 -```
148 -start()
149 -stop()
150 -status()
151 -```
152 -
153 -There are default implementations in `lib/rc/sh/openrc-run.sh` - this allows very
154 -compact service scripts. These functions can be overridden per service script as
155 -needed.
156 -
157 -The default functions assume the following variables to be set in the service
158 -script:
159 -
160 -```
161 -command=
162 -command_args=
163 -pidfile=
164 -```
165 -
166 -Thus the 'smallest' service scripts can be half a dozen lines long
167 -
168 # The Magic of `conf.d`
169
170 Most service scripts need default values. It would be fragile to
171 @@ -217,7 +108,7 @@ start() {
172 }
173 ```
174
175 -The big advantage of this split is that most of the time editing of the init
176 +The big advantage of this split is that most of the time editing of the service
177 script can be avoided.
178
179 # Start-Stop-Daemon
180 @@ -271,7 +162,7 @@ happen automatically when the service is stopped.
181
182 # Caching
183
184 -For performance reasons OpenRC keeps a cache of pre-parsed initscript metadata
185 +For performance reasons OpenRC keeps a cache of pre-parsed service metadata
186 (e.g. `depend`). The default location for this is `/${RC_SVCDIR}/cache`.
187
188 The cache uses `mtime` to check for file staleness. Should any service script
189 @@ -281,5 +172,5 @@ change it'll re-source the relevant files and update the cache
190
191 OpenRC has wrappers for many common output tasks in libeinfo.
192 This allows to print colour-coded status notices and other things.
193 -To make the output consistent the bundled initscripts all use ebegin/eend to
194 +To make the output consistent the bundled service scripts all use ebegin/eend to
195 print nice messages.
196
197 diff --git a/service-script-guide.md b/service-script-guide.md
198 index 668d05d4..4839e1b4 100644
199 --- a/service-script-guide.md
200 +++ b/service-script-guide.md
201 @@ -13,6 +13,115 @@ don't consider anything exotic, and assume that you will use
202 start-stop-daemon to manage a fairly typical long-running UNIX
203 process.
204
205 +## Syntax of Service Scripts
206 +
207 +Service scripts are shell scripts. OpenRC aims at using only the standardized
208 +POSIX sh subset for portability reasons. The default interpreter (build-time
209 +toggle) is `/bin/sh`, so using for example mksh is not a problem.
210 +
211 +OpenRC has been tested with busybox sh, ash, dash, bash, mksh, zsh and possibly
212 +others. Using busybox sh has been difficult as it replaces commands with
213 +builtins that don't offer the expected features.
214 +
215 +The interpreter for service scripts is `#!/sbin/openrc-run`.
216 +Not using this interpreter will break the use of dependencies and is not
217 +supported. (iow: if you insist on using `#!/bin/sh` you're on your own)
218 +
219 +A `depend` function declares the dependencies of this service script.
220 +All scripts must have start/stop/status functions, but defaults are provided and should be used unless you have a very strong reason not to use them.
221 +
222 +Extra functions can be added easily:
223 +
224 +```
225 +extra_commands="checkconfig"
226 +checkconfig() {
227 + doSomething
228 +}
229 +```
230 +
231 +This exports the checkconfig function so that `/etc/init.d/someservice
232 +checkconfig` will be available, and it "just" runs this function.
233 +
234 +While commands defined in `extra_commands` are always available, commands
235 +defined in `extra_started_commands` will only work when the service is started
236 +and those defined in `extra_stopped_commands` will only work when the service is
237 +stopped. This can be used for implementing graceful reload and similar
238 +behaviour.
239 +
240 +Adding a restart function will not work, this is a design decision within
241 +OpenRC. Since there may be dependencies involved (e.g. network -> apache) a
242 +restart function is in general not going to work.
243 +restart is internally mapped to `stop()` + `start()` (plus handling dependencies).
244 +If a service needs to behave differently when it is being restarted vs
245 +started or stopped, it should test the `$RC_CMD` variable, for example:
246 +
247 +```
248 +[ "$RC_CMD" = restart ] && do_something
249 +```
250 +
251 +## The Depend Function
252 +
253 +This function declares the dependencies for a service script. This
254 +determines the order the service scripts start.
255 +
256 +```
257 +depend() {
258 + need net
259 + use dns logger netmount
260 + want coolservice
261 +}
262 +```
263 +
264 +`need` declares a hard dependency - net always needs to be started before this
265 + service does
266 +
267 +`use` is a soft dependency - if dns, logger or netmount is in this runlevel
268 + start it before, but we don't care if it's not in this runlevel.
269 + `want` is between need and use - try to start coolservice if it is
270 + installed on the system, regardless of whether it is in the
271 + runlevel, but we don't care if it starts.
272 +
273 +`before` declares that we need to be started before another service
274 +
275 +`after` declares that we need to be started after another service, without
276 + creating a dependency (so on calling stop the two are independent)
277 +
278 +`provide` allows multiple implementations to provide one service type, e.g.:
279 + `provide cron` is set in all cron-daemons, so any one of them started
280 + satisfies a cron dependency
281 +
282 +`keyword` allows platform-specific overrides, e.g. `keyword -lxc` makes this
283 + service script a noop in lxc containers. Useful for things like keymaps,
284 + module loading etc. that are either platform-specific or not available
285 + in containers/virtualization/...
286 +
287 +FIXME: Anything missing in this list?
288 +
289 +## The Default Functions
290 +
291 +All service scripts are assumed to have the following functions:
292 +
293 +```
294 +start()
295 +stop()
296 +status()
297 +```
298 +
299 +There are default implementations in `lib/rc/sh/openrc-run.sh` - this allows very
300 +compact service scripts. These functions can be overridden per service script as
301 +needed.
302 +
303 +The default functions assume the following variables to be set in the service
304 +script:
305 +
306 +```
307 +command=
308 +command_args=
309 +pidfile=
310 +```
311 +
312 +Thus the 'smallest' service scripts can be half a dozen lines long
313 +
314 ## Don't write your own start/stop functions
315
316 OpenRC is capable of stopping and starting most daemons based on the