From 6368df5e37cb391811ec2967bc53e77fe8d2f942 Mon Sep 17 00:00:00 2001 From: Pascal Vizeli Date: Tue, 24 May 2022 15:51:06 +0200 Subject: [PATCH] Base Image: S6 overlay & jemalloc update (#72425) * Update base image with new s6-Overlay & jemalloc * add build version * Update finish --- build.yaml | 10 +-- rootfs/etc/services.d/home-assistant/finish | 42 +++++++------ rootfs/etc/services.d/home-assistant/run | 0 rootfs/init | 70 ++++++++++++++------- 4 files changed, 77 insertions(+), 45 deletions(-) mode change 100644 => 100755 rootfs/etc/services.d/home-assistant/finish mode change 100644 => 100755 rootfs/etc/services.d/home-assistant/run diff --git a/build.yaml b/build.yaml index 3ced7b8d742b1..196277184a31b 100644 --- a/build.yaml +++ b/build.yaml @@ -1,11 +1,11 @@ image: homeassistant/{arch}-homeassistant shadow_repository: ghcr.io/home-assistant build_from: - aarch64: ghcr.io/home-assistant/aarch64-homeassistant-base:2022.02.0 - armhf: ghcr.io/home-assistant/armhf-homeassistant-base:2022.02.0 - armv7: ghcr.io/home-assistant/armv7-homeassistant-base:2022.02.0 - amd64: ghcr.io/home-assistant/amd64-homeassistant-base:2022.02.0 - i386: ghcr.io/home-assistant/i386-homeassistant-base:2022.02.0 + aarch64: ghcr.io/home-assistant/aarch64-homeassistant-base:2022.05.0 + armhf: ghcr.io/home-assistant/armhf-homeassistant-base:2022.05.0 + armv7: ghcr.io/home-assistant/armv7-homeassistant-base:2022.05.0 + amd64: ghcr.io/home-assistant/amd64-homeassistant-base:2022.05.0 + i386: ghcr.io/home-assistant/i386-homeassistant-base:2022.05.0 codenotary: signer: notary@home-assistant.io base_image: notary@home-assistant.io diff --git a/rootfs/etc/services.d/home-assistant/finish b/rootfs/etc/services.d/home-assistant/finish old mode 100644 new mode 100755 index 3691583ec81da..115d835261806 --- a/rootfs/etc/services.d/home-assistant/finish +++ b/rootfs/etc/services.d/home-assistant/finish @@ -1,24 +1,30 @@ -#!/usr/bin/execlineb -S1 +#!/usr/bin/env bashio # ============================================================================== # Take down the S6 supervision tree when Home Assistant fails # ============================================================================== -define HA_RESTART_EXIT_CODE 100 -define SIGNAL_EXIT_CODE 256 -define SIGTERM 15 +declare RESTART_EXIT_CODE 100 +declare SIGNAL_EXIT_CODE 256 +declare SIGTERM 15 +declare APP_EXIT_CODE=${1} +declare SYS_EXIT_CODE=${2+x} +declare NEW_EXIT_CODE= -foreground { s6-echo "[finish] process exit code ${1}" } +bashio::log.info "Home Assistant Core finish process exit code ${1}" -if { s6-test ${1} -ne ${HA_RESTART_EXIT_CODE} } -ifelse { s6-test ${1} -eq ${SIGNAL_EXIT_CODE} } { - # Process terminated by a signal - define signal ${2} - foreground { s6-echo "[finish] process received signal ${signal}" } - backtick -n new_exit_code { s6-expr 128 + ${signal} } - importas -ui new_exit_code new_exit_code - foreground { redirfd -w 1 /var/run/s6/env-stage3/S6_STAGE2_EXITED s6-echo -n -- ${new_exit_code} } - if { s6-test ${signal} -ne ${SIGTERM} } - s6-svscanctl -t /var/run/s6/services -} +if [[ ${APP_EXIT_CODE} -eq ${RESTART_EXIT_CODE} ]]; then + exit 0 +elif [[ ${APP_EXIT_CODE} -eq ${SIGNAL_EXIT_CODE} ]]; then + bashio::log.info "Home Assistant Core finish process received signal ${APP_EXIT_CODE}" -foreground { redirfd -w 1 /var/run/s6/env-stage3/S6_STAGE2_EXITED s6-echo -n -- ${1} } -s6-svscanctl -t /var/run/s6/services + NEW_EXIT_CODE=$((128 + SYS_EXIT_CODE)) + echo ${NEW_EXIT_CODE} > /run/s6-linux-init-container-results/exitcode + + if [[ ${NEW_EXIT_CODE} -eq ${SIGTERM} ]]; then + /run/s6/basedir/bin/halt + fi +else + bashio::log.info "Home Assistant Core service shutdown" + + echo ${APP_EXIT_CODE} > /run/s6-linux-init-container-results/exitcode + /run/s6/basedir/bin/halt +fi diff --git a/rootfs/etc/services.d/home-assistant/run b/rootfs/etc/services.d/home-assistant/run old mode 100644 new mode 100755 diff --git a/rootfs/init b/rootfs/init index 7bea7ed88a91e..bfc4802c85855 100755 --- a/rootfs/init +++ b/rootfs/init @@ -1,23 +1,49 @@ -#!/bin/execlineb -S0 - -## -## load default PATH (the same that Docker includes if not provided) if it doesn't exist, -## then go ahead with stage1. -## this was motivated due to this issue: -## - https://github.com/just-containers/s6-overlay/issues/108 -## - -/bin/importas -D /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PATH PATH -export PATH ${PATH} - -## -## Skip further init if the user has a given CMD. -## This is to prevent Home Assistant from starting twice if the user -## decided to override/start via the CMD. -## - -ifelse { s6-test $# -ne 0 } -{ - $@ +#!/usr/bin/env bashio + +# This is the first program launched at container start. +# We don't know where our binaries are and we cannot guarantee +# that the default PATH can access them. +# So this script needs to be entirely self-contained until it has +# at least /command, /usr/bin and /bin in its PATH. + +addpath () { + x="$1" + IFS=: + set -- $PATH + IFS= + while test "$#" -gt 0 ; do + if test "$1" = "$x" ; then + return + fi + shift + done + PATH="${x}:$PATH" } -/etc/s6/init/init-stage1 $@ \ No newline at end of file + +if test -z "$PATH" ; then + PATH=/bin +fi + +addpath /bin +addpath /usr/bin +addpath /command +export PATH + +# Now we're good: s6-overlay-suexec is accessible via PATH, as are +# all our binaries. + +# Skip further init if the user has a given CMD. +# This is to prevent Home Assistant from starting twice if the user +# decided to override/start via the CMD. +if test $# -ne 0 ; then + exec "$@" +fi + +# Run preinit as root, then run stage0 as the container's user (can be +# root, can be a normal user). + +exec s6-overlay-suexec \ + ' /package/admin/s6-overlay-@VERSION@/libexec/preinit' \ + '' \ + /package/admin/s6-overlay-@VERSION@/libexec/stage0 \ + "$@"