Provide a way of determining init system used

dib-init-system script is installed into $PATH. Called
without arguments it will print the name of init system
used to stdout.

Additionally, set DIB_INIT_SYSTEM environment variable to
the init system used.

Tested on ubuntu+upstart, centos+upstart, fedora+systemd,
debian+sysv.

Closes-Bug: #1251610

Change-Id: I29668079091f6060dab66d8259890384d3bbd653
This commit is contained in:
Roman Podoliaka 2013-11-15 15:21:56 +02:00
parent 35830cc57c
commit b01c73aadc
3 changed files with 24 additions and 0 deletions

18
elements/base/dib-init-system Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
set -eu
if [ -f /sbin/initctl ]; then
echo "upstart"
elif [ -f /usr/bin/systemctl ]; then
echo "systemd"
elif [ -f /sbin/init ]; then
if [ -f /bin/systemd ]; then
echo "systemd"
else
echo "sysv"
fi
else
echo "Unknown init system"
exit 1
fi

View File

@ -0,0 +1 @@
export DIB_INIT_SYSTEM=$(dib-init-system)

View File

@ -0,0 +1,5 @@
#!/bin/bash
set -e
install -m 0755 -o root -g root $(dirname $0)/../dib-init-system /usr/bin/