Gentoo Archives: gentoo-dev

From: Brian Evans <grknight@g.o>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Common options missed in OpenRC declarative scripts and how to improve them
Date: Thu, 02 Dec 2021 02:02:29
Message-Id: 85f60100-3d55-5905-9db1-d1abb37283e6@gentoo.org
1 After a cursory scan of the Gentoo repository, I've noticed an
2 overabundance of start_stop_daemon_args being declared in scripts committed.
3
4 I would like to draw attention and see if we can clean these up together.
5
6 The reason why these are important is the modular nature of the
7 declarative syntax. For example, supervise-daemon should be available to
8 any user for a declarative script by simply adding
9 supervisor="supervise-daemon" to the corresponding conf.d file.
10
11 There are many necessary options like --wait or --env which don't have a
12 declarative replacement.
13
14 These comments are for scripts without a start/stop function defined
15 thereby relying on the default scripts in /lib/rc/sh/. There are other
16 advanced cases for sure. I just want to discuss easy to forget options.
17
18 Common mistakes included with start_stop_daemon_args:
19
20 "--background --make-pidfile" ("-b -m") should be replaced by
21 command_background="yes" (these are implied together)
22
23 "--user" and/or "--group" should be command_user="user:group" (use root
24 for user when only group is needed, the :group can be omitted)
25
26 "--chdir /path/to/foo" (-d) should be directory="/path/to/foo"
27
28 "--chroot /var/chroot/foo" (-r) should be chroot="/var/chroot/foo"
29
30 "--stdout /var/log/foo" (-1) should be output_log="/var/log/foo"
31
32 "--stderr /var/log/foo.err" (-2) should be error_log="/var/log/foo.err"
33
34 "--pidifle /run/foo.pid" (-p) should be pidfile="/run/foo.pid"
35
36 "--name foo" (-n) should be procname="foo"
37
38 "--exec" (-x) should be deleted as it is included by default when
39 command="" is declared (required to exist)
40
41 In addition, command_args may need to be reevaluated for each script to
42 split certain pieces out into command_args_foreground and
43 command_args_background.
44
45 command_args_foreground should include any options to force the
46 daemon/script into the foreground instead of forking.
47
48 command_args_background should include any option to fork a daemon and,
49 optionally, to have it write a pidfile to monitor. (Cannot be used
50 together with command_background option).
51
52 command_args should not include the conditions of the other two in most
53 cases.
54
55 If anyone would want me to do work in obvious cleanups, I am open to
56 bugs, patches or just committing.
57
58 Comments welcome.
59
60 Brian

Attachments

File name MIME type
OpenPGP_signature.asc application/pgp-signature

Replies