Browse Source

Merge "Introduce manual setting of DIB_INIT_SYSTEM"

tags/2.30.0
Zuul 2 weeks ago
parent
commit
6143d40def
12 changed files with 72 additions and 41 deletions
  1. +1
    -0
      diskimage_builder/elements/debian-minimal/environment.d/10-debian-minimal.bash
  2. +4
    -5
      diskimage_builder/elements/dib-init-system/README.rst
  3. +0
    -33
      diskimage_builder/elements/dib-init-system/dib-init-system
  4. +0
    -2
      diskimage_builder/elements/dib-init-system/environment.d/10-dib-init-system.bash
  5. +30
    -0
      diskimage_builder/elements/dib-init-system/environment.d/99-dib-init-system
  6. +13
    -1
      diskimage_builder/elements/dib-init-system/pre-install.d/04-dib-init-system
  7. +2
    -0
      diskimage_builder/elements/gentoo/environment.d/00-gentoo-envars.bash
  8. +1
    -0
      diskimage_builder/elements/opensuse-minimal/environment.d/10-opensuse-distro-name.bash
  9. +1
    -0
      diskimage_builder/elements/opensuse/environment.d/10-opensuse-distro-name.bash
  10. +1
    -0
      diskimage_builder/elements/redhat-common/environment.d/50-redhat-common
  11. +5
    -0
      diskimage_builder/elements/ubuntu-common/environment.d/11-ubuntu-init-system.bash
  12. +14
    -0
      releasenotes/notes/dib-init-system-5647bad17a01c602.yaml

+ 1
- 0
diskimage_builder/elements/debian-minimal/environment.d/10-debian-minimal.bash View File

@@ -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

+ 4
- 5
diskimage_builder/elements/dib-init-system/README.rst View File

@@ -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.

+ 0
- 33
diskimage_builder/elements/dib-init-system/dib-init-system View File

@@ -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

+ 0
- 2
diskimage_builder/elements/dib-init-system/environment.d/10-dib-init-system.bash View File

@@ -1,2 +0,0 @@
DIB_INIT_SYSTEM=$(PATH="$PATH:$(dirname $BASH_SOURCE)/.." dib-init-system)
export DIB_INIT_SYSTEM

+ 30
- 0
diskimage_builder/elements/dib-init-system/environment.d/99-dib-init-system View File

@@ -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:

+ 13
- 1
diskimage_builder/elements/dib-init-system/pre-install.d/04-dib-init-system View File

@@ -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} <<EOF
#!/bin/bash
echo ${DIB_INIT_SYSTEM}
EOF

chown root:root ${FILE}
chmod 775 ${FILE}

+ 2
- 0
diskimage_builder/elements/gentoo/environment.d/00-gentoo-envars.bash View File

@@ -21,3 +21,5 @@ fi
for (( i=0; i<${#GENTOO_EMERGE_ENV[@]}; i++ )); do
eval export "${GENTOO_EMERGE_ENV[i]}"
done

export DIB_INIT_SYSTEM=systemd

+ 1
- 0
diskimage_builder/elements/opensuse-minimal/environment.d/10-opensuse-distro-name.bash View File

@@ -2,3 +2,4 @@ export DISTRO_NAME=opensuse
DIB_RELEASE=${DIB_RELEASE:-15.1}
export DIB_RELEASE=${DIB_RELEASE,,}
export DIB_OPENSUSE_PATTERNS=patterns-openSUSE-base
export DIB_INIT_SYSTEM=systemd

+ 1
- 0
diskimage_builder/elements/opensuse/environment.d/10-opensuse-distro-name.bash View File

@@ -1,6 +1,7 @@
export DISTRO_NAME=opensuse
export DIB_RELEASE=${DIB_RELEASE:-15.1}
export DIB_OPENSUSE_PATTERNS=patterns-openSUSE-base
export DIB_INIT_SYSTEM=systemd
case ${DIB_RELEASE} in
# Old Leap releases
42*) export OPENSUSE_REPO_DIR=openSUSE_Leap_${DIB_RELEASE} ;;

+ 1
- 0
diskimage_builder/elements/redhat-common/environment.d/50-redhat-common View File

@@ -1 +1,2 @@
export DIB_DISABLE_KERNEL_CLEANUP=${DIB_DISABLE_KERNEL_CLEANUP:-0}
export DIB_INIT_SYSTEM=systemd

+ 5
- 0
diskimage_builder/elements/ubuntu-common/environment.d/11-ubuntu-init-system.bash View File

@@ -0,0 +1,5 @@
if [[ ${DIB_RELEASE} == "trusty" ]]; then
export DIB_INIT_SYSTEM=upstart
else
export DIB_INIT_SYSTEM=systemd
fi

+ 14
- 0
releasenotes/notes/dib-init-system-5647bad17a01c602.yaml View File

@@ -0,0 +1,14 @@
---
deprecations:
- |
The ``dib-init-system`` element installs a utility
``/usr/local/bin/dib-init-system`` which would try to guess the
init system (systemd, etc.). This was called from
``environment.d`` files, which means that in phases outside the
chroot it was attempting to query the init system of the build
host. This completely fails in a situation such as running inside
a container without a full init system. To avoid this issue, each
OS element will set DIB_INIT_SYSTEM directly. The
``dib-init-system`` script was not really intended to be called
directly, but will now just report the value of
``DIB_INIT_SYSTEM``.

Loading…
Cancel
Save