Merge "Introduce manual setting of DIB_INIT_SYSTEM"

This commit is contained in:
Zuul 2019-11-22 06:43:25 +00:00 committed by Gerrit Code Review
commit 6143d40def
12 changed files with 72 additions and 41 deletions

View File

@ -1,5 +1,6 @@
export DISTRO_NAME=debian export DISTRO_NAME=debian
export DIB_RELEASE=${DIB_RELEASE:-stable} export DIB_RELEASE=${DIB_RELEASE:-stable}
export DIB_INIT_SYSTEM=systemd
if [ -n "${DIB_DEBIAN_DISTRIBUTION_MIRROR:-}" ]; then if [ -n "${DIB_DEBIAN_DISTRIBUTION_MIRROR:-}" ]; then
DIB_DISTRIBUTION_MIRROR=$DIB_DEBIAN_DISTRIBUTION_MIRROR DIB_DISTRIBUTION_MIRROR=$DIB_DEBIAN_DISTRIBUTION_MIRROR

View File

@ -2,9 +2,7 @@
dib-init-system dib-init-system
=============== ===============
Installs a script (dib-init-system) which outputs the type of init system in Element that handles aspects of the used target's init system.
use on the target image. Also sets an environment variable ``DIB_INIT_SYSTEM``
to this value.
Any files placed in a ``init-scripts/INIT_SYSTEM`` directory inside the Any files placed in a ``init-scripts/INIT_SYSTEM`` directory inside the
element will be copied into the appropriate directory if ``INIT_SYSTEM`` element will be copied into the appropriate directory if ``INIT_SYSTEM``
@ -14,5 +12,6 @@ Environment Variables
--------------------- ---------------------
DIB_INIT_SYSTEM DIB_INIT_SYSTEM
:Description: One of upstart, systemd, or sysv depending on the init system :Description: One of ``upstart``, ``systemd``, ``openrc`` or
in use for the target image. ``sysv`` depending on the init system in use for the target image.
This should be set automatically by your platform elements.

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

View File

@ -1,2 +0,0 @@
DIB_INIT_SYSTEM=$(PATH="$PATH:$(dirname $BASH_SOURCE)/.." dib-init-system)
export 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:

View File

@ -6,4 +6,16 @@ fi
set -eu set -eu
set -o pipefail 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}

View File

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

View File

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

View File

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

View File

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

View File

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

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