From 3636b40f74f5bbfedfa8bb3e132b4128270ac64b Mon Sep 17 00:00:00 2001 From: Andreas Florath Date: Sun, 2 Apr 2017 18:26:13 +0000 Subject: [PATCH] Introduce manual setting of DIB_INIT_SYSTEM The current implementation evauates the dib-init-system script too early. Also it looks that there is no simple way of getting the info about the init system automatically: another element can install (later on) a different init system. Therefore the only reliable way of setting this is manual. Change-Id: I6e9ffa1bdb3154f488f4fd335b197699b86aacd4 Signed-off-by: Andreas Florath --- .../environment.d/10-debian-minimal.bash | 1 + .../elements/dib-init-system/README.rst | 9 +++-- .../elements/dib-init-system/dib-init-system | 33 ------------------- .../environment.d/10-dib-init-system.bash | 2 -- .../environment.d/99-dib-init-system | 30 +++++++++++++++++ .../pre-install.d/04-dib-init-system | 14 +++++++- .../environment.d/00-gentoo-envars.bash | 2 ++ .../10-opensuse-distro-name.bash | 1 + .../10-opensuse-distro-name.bash | 1 + .../environment.d/50-redhat-common | 1 + .../environment.d/11-ubuntu-init-system.bash | 5 +++ .../dib-init-system-5647bad17a01c602.yaml | 14 ++++++++ 12 files changed, 72 insertions(+), 41 deletions(-) delete mode 100755 diskimage_builder/elements/dib-init-system/dib-init-system delete mode 100644 diskimage_builder/elements/dib-init-system/environment.d/10-dib-init-system.bash create mode 100644 diskimage_builder/elements/dib-init-system/environment.d/99-dib-init-system create mode 100644 diskimage_builder/elements/ubuntu-common/environment.d/11-ubuntu-init-system.bash create mode 100644 releasenotes/notes/dib-init-system-5647bad17a01c602.yaml diff --git a/diskimage_builder/elements/debian-minimal/environment.d/10-debian-minimal.bash b/diskimage_builder/elements/debian-minimal/environment.d/10-debian-minimal.bash index acaa6f33..62f95fe9 100644 --- a/diskimage_builder/elements/debian-minimal/environment.d/10-debian-minimal.bash +++ b/diskimage_builder/elements/debian-minimal/environment.d/10-debian-minimal.bash @@ -1,5 +1,6 @@ export DISTRO_NAME=debian export DIB_RELEASE=${DIB_RELEASE:-stable} +export DIB_INIT_SYSTEM=systemd if [ -n "${DIB_DEBIAN_DISTRIBUTION_MIRROR:-}" ]; then DIB_DISTRIBUTION_MIRROR=$DIB_DEBIAN_DISTRIBUTION_MIRROR diff --git a/diskimage_builder/elements/dib-init-system/README.rst b/diskimage_builder/elements/dib-init-system/README.rst index b2c34383..b7d3423b 100644 --- a/diskimage_builder/elements/dib-init-system/README.rst +++ b/diskimage_builder/elements/dib-init-system/README.rst @@ -2,9 +2,7 @@ dib-init-system =============== -Installs a script (dib-init-system) which outputs the type of init system in -use on the target image. Also sets an environment variable ``DIB_INIT_SYSTEM`` -to this value. +Element that handles aspects of the used target's init system. Any files placed in a ``init-scripts/INIT_SYSTEM`` directory inside the element will be copied into the appropriate directory if ``INIT_SYSTEM`` @@ -14,5 +12,6 @@ Environment Variables --------------------- DIB_INIT_SYSTEM - :Description: One of upstart, systemd, or sysv depending on the init system - in use for the target image. + :Description: One of ``upstart``, ``systemd``, ``openrc`` or + ``sysv`` depending on the init system in use for the target image. + This should be set automatically by your platform elements. diff --git a/diskimage_builder/elements/dib-init-system/dib-init-system b/diskimage_builder/elements/dib-init-system/dib-init-system deleted file mode 100755 index 48164d3d..00000000 --- a/diskimage_builder/elements/dib-init-system/dib-init-system +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -if [ ${DIB_DEBUG_TRACE:-0} -gt 0 ]; then - set -x -fi -set -eu -set -o pipefail - -# Debian Jessie and Debian Stretch use /bin/systemctl. -# (/sbin/init is only available if systemd-sysv is installed.) - -if [ -f /usr/bin/systemctl -o -f /bin/systemctl ]; then - echo "systemd" -elif [[ -f /sbin/initctl ]]; then - echo "upstart" -elif [[ -f /etc/gentoo-release ]]; then - if [[ -z GENTOO_PROFILE ]]; then - if [[ "${GENTOO_PROFILE}" =~ systemd ]]; then - echo "systemd" - fi - else - echo "openrc" - fi -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/diskimage_builder/elements/dib-init-system/environment.d/10-dib-init-system.bash b/diskimage_builder/elements/dib-init-system/environment.d/10-dib-init-system.bash deleted file mode 100644 index d683ce89..00000000 --- a/diskimage_builder/elements/dib-init-system/environment.d/10-dib-init-system.bash +++ /dev/null @@ -1,2 +0,0 @@ -DIB_INIT_SYSTEM=$(PATH="$PATH:$(dirname $BASH_SOURCE)/.." dib-init-system) -export DIB_INIT_SYSTEM diff --git a/diskimage_builder/elements/dib-init-system/environment.d/99-dib-init-system b/diskimage_builder/elements/dib-init-system/environment.d/99-dib-init-system new file mode 100644 index 00000000..958a6e90 --- /dev/null +++ b/diskimage_builder/elements/dib-init-system/environment.d/99-dib-init-system @@ -0,0 +1,30 @@ +# +# This runs last in the environment to ensure DIB_INIT_SYSTEM is set. +# We expect the base environments to set this variable particular to +# their platform. Note we used to try and guess this automatically +# inside the chroot, but there's a chicken-and-egg issue when you're +# building from scratch and you're guessing before you've even +# installed the init system. +# + +if [ -z "${DIB_INIT_SYSTEM:-}" ]; then + echo "DIB_INIT_SYSTEM is not set! Can not continue" + exit 1 +fi + +# whitelist known systems +case $DIB_INIT_SYSTEM in + upstart) ;; + openrc) ;; + systemd) ;; + sysv) ;; + *) + echo "Unrecognised init system: ${DIB_INIT_SYSTEM}!" + echo "Can not continue" + exit 1 +esac + +# Tell emacs to use shell-mode +# Local variables: +# mode: sh +# End: diff --git a/diskimage_builder/elements/dib-init-system/pre-install.d/04-dib-init-system b/diskimage_builder/elements/dib-init-system/pre-install.d/04-dib-init-system index 8e63fcd2..36f5bd79 100755 --- a/diskimage_builder/elements/dib-init-system/pre-install.d/04-dib-init-system +++ b/diskimage_builder/elements/dib-init-system/pre-install.d/04-dib-init-system @@ -6,4 +6,16 @@ fi set -eu set -o pipefail -install -m 0755 -o root -g root $(dirname $0)/../dib-init-system /usr/bin/ +FILE=/usr/local/bin/dib-init-system + +# This is a dummy script that simply echos the output of +# ${DIB_INIT_SYSTEM}. This script used to try and guess the init +# system, but that doesn't work. This script is deprecated. + +cat > ${FILE} <