Walter Dnes posted on Sat, 30 Sep 2017 00:20:31 -0400 as excerpted: > But, how do we reliably detect the currently running init system? Are > there running processes, or entries in /sys/ or /proc/ or /dev that are > unique to to each init system?
In theory at least, that's easy enough, just check the kernel commandline's (/proc/cmdline) init= if present, and fall back to matching against the path (canonical, to take care of symlink-based init- switching) of PID 1 if init= isn't present or points to the default /sbin/init. In practice I suspect one would need to arrange for each supported init system to drop its own detection executable in place, making the script something like this: #!/bin/bash initdetectpath=/lib/initdetect if ${initdetectpath}/issystemd ; then ... elif ${initdetectpath}/isopenrc ; then ... But, once you're having the initsystems package their own detection files, you might as well simply make them their own service scripts designed to do the detection as well, returning a specified error code if it's not that initsystem, making it as simple as: #!/bin/bash notme=<magicreturncode> for $servicefile in /lib/initservicedir/* ; do $servicefile "$@" code=$? [[ $code = $notme ]] || break done [[ $code = $notme ]] && / echo "No supported initsystem claimed to be running" > /dev/stderr exit $code Then it's up to the initsys packagers whether they want to support the scheme or not, what sort of detection they do if they support it, and how they translate the passed parameters if necessary, and bugs in how they do any of it become the bugs of that initsystem. -- Duncan - List replies preferred. No HTML msgs. "Every nonfree program has a lord, a master -- and if you use the program, he is your master." Richard Stallman