The "official" way to detect if systemd is running appears to be to
check if the directory /run/systemd/system exists (from sd_booted(3)).
Our init-system-helpers package uses this test for example, and the test
correctly handles edge cases where one init system is installed but
another is in use such as when Trusty is upgraded to Xenial but has not
been rebooted yet.
However, the systemd SRU to Trusty in bug 1656280 regressed the
result of this test, resulting in bug 1732703.
Rather than have an ad-hoc solution I feel is brittle in case we have to
SRU systemd in Trusty again, I'd prefer to have consensus on what
Ubuntu's position is on checking the init system in use, and then we can
make sure to be consistent across all packages and (if possible) all
I see three options:
1) Fix systemd on Trusty so that testing for /run/systemd/system works
again. This will probably need to remove /run/systemd/system correctly
on postinst as part of the fix. This will unbreak MAAS and snapd working
2) Come up with and agree on some other universal way for testing for
systemd and make that work everywhere. Then we can SRU that test to MAAS
in Trusty, and fix any other packages in Trusty affected by the
behaviour change of the original test.
3) Accept that on Trusty the general case is now broken, and make the
official test be something like the following. This will need to be
SRU'd to MAAS in Trusty, and we'll need to fix any other packages in
Trusty affected by the behaviour change of the original test.
if Trusty: upstart
else if [ -d /run/systemd/system ]: systemd
else [existing checks for other init systems]
Are there any other options? Please discuss as you wish. My purpose in
starting this thread is to record consensus once we have it, so the
archive of this thread can be used to be consistent in how we handle
It occurs to me that another class of use cases the test behaviour
change might have broken are configuration management tools, which all
generally need to know what init system is in use in order to manage
services. I have not investigated this though.