From b01c73aadc08ac1cb1855c38f74a1e995efea221 Mon Sep 17 00:00:00 2001 From: Roman Podoliaka Date: Fri, 15 Nov 2013 15:21:56 +0200 Subject: [PATCH] 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 --- elements/base/dib-init-system | 18 ++++++++++++++++++ .../base/environment.d/10-dib-init-system.bash | 1 + elements/base/pre-install.d/04-dib-init-system | 5 +++++ 3 files changed, 24 insertions(+) create mode 100755 elements/base/dib-init-system create mode 100644 elements/base/environment.d/10-dib-init-system.bash create mode 100755 elements/base/pre-install.d/04-dib-init-system diff --git a/elements/base/dib-init-system b/elements/base/dib-init-system new file mode 100755 index 00000000..88cf5fae --- /dev/null +++ b/elements/base/dib-init-system @@ -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 diff --git a/elements/base/environment.d/10-dib-init-system.bash b/elements/base/environment.d/10-dib-init-system.bash new file mode 100644 index 00000000..f264a23a --- /dev/null +++ b/elements/base/environment.d/10-dib-init-system.bash @@ -0,0 +1 @@ +export DIB_INIT_SYSTEM=$(dib-init-system) diff --git a/elements/base/pre-install.d/04-dib-init-system b/elements/base/pre-install.d/04-dib-init-system new file mode 100755 index 00000000..54ea2587 --- /dev/null +++ b/elements/base/pre-install.d/04-dib-init-system @@ -0,0 +1,5 @@ +#!/bin/bash + +set -e + +install -m 0755 -o root -g root $(dirname $0)/../dib-init-system /usr/bin/