Gentoo Archives: gentoo-dev

From: Duncan <1i5t5.duncan@×××.net>
To: gentoo-dev@l.g.o
Subject: [gentoo-dev] Re: Providing a `service` scripts that speaks OpenRC and systemd
Date: Sat, 30 Sep 2017 21:32:44
Message-Id: pan$a2e62$1ff46979$8dfa53a2$ae25ad8b@cox.net
In Reply to: Re: [gentoo-dev] Providing a `service` scripts that speaks OpenRC and systemd by Walter Dnes
1 Walter Dnes posted on Sat, 30 Sep 2017 00:20:31 -0400 as excerpted:
2
3 > But, how do we reliably detect the currently running init system? Are
4 > there running processes, or entries in /sys/ or /proc/ or /dev that are
5 > unique to to each init system?
6
7 In theory at least, that's easy enough, just check the kernel
8 commandline's (/proc/cmdline) init= if present, and fall back to matching
9 against the path (canonical, to take care of symlink-based init-
10 switching) of PID 1 if init= isn't present or points to the default
11 /sbin/init.
12
13 In practice I suspect one would need to arrange for each supported init
14 system to drop its own detection executable in place, making the script
15 something like this:
16
17 #!/bin/bash
18 initdetectpath=/lib/initdetect
19 if ${initdetectpath}/issystemd ; then
20 ...
21 elif ${initdetectpath}/isopenrc ; then
22 ...
23
24
25 But, once you're having the initsystems package their own detection
26 files, you might as well simply make them their own service scripts
27 designed to do the detection as well, returning a specified error code if
28 it's not that initsystem, making it as simple as:
29
30 #!/bin/bash
31 notme=<magicreturncode>
32
33 for $servicefile in /lib/initservicedir/* ; do
34 $servicefile "$@"
35 code=$?
36 [[ $code = $notme ]] || break
37 done
38
39 [[ $code = $notme ]] && /
40 echo "No supported initsystem claimed to be running" > /dev/stderr
41 exit $code
42
43
44 Then it's up to the initsys packagers whether they want to support the
45 scheme or not, what sort of detection they do if they support it, and how
46 they translate the passed parameters if necessary, and bugs in how they
47 do any of it become the bugs of that initsystem.
48
49 --
50 Duncan - List replies preferred. No HTML msgs.
51 "Every nonfree program has a lord, a master --
52 and if you use the program, he is your master." Richard Stallman

Replies