From a118209706ca604ca8be2b0bd102062aff8133cb Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Wed, 20 Mar 2024 17:23:39 +0000 Subject: [PATCH 1/5] remove S6 settings which are no longer necessary S6_BEHAVIOUR_IF_STAGE2_FAILS only affects v2 legacy services and init scripts, thus it has no effect on the current code S6_SERVICES_GRACETIME only applies to v2 legacy services and does not apply to the current code S6_KILL_GRACETIME (default 3000 milliseconds) After all services are stopped, SIGTERM is sent to all remaining processes. s6 then waits S6_KILL_GRACETIME and sends SIGKILL to all remaining processes. This gracetime is never skipped even if there are no remaining processes. After services are stopped, no processes should be remaining if the services are started correctly, which is currently the case for this container. readsb / collectd now stop correctly as part of the services being stopped and don't need this anymore to stop cleanly --- Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index ff1ed55..9dbab45 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,10 +5,7 @@ FROM ghcr.io/sdr-enthusiasts/docker-baseimage:wreadsb -ENV S6_BEHAVIOUR_IF_STAGE2_FAILS=2 \ - S6_SERVICES_GRACETIME=20000 \ - S6_KILL_GRACETIME=20000 \ - BEASTPORT=30005 \ +ENV BEASTPORT=30005 \ GITPATH_TIMELAPSE1090=/opt/timelapse1090 \ HTTP_ACCESS_LOG="false" \ HTTP_ERROR_LOG="true" \ From 846111e6020f4fdcf45e257d2b0227b502b898b1 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Wed, 20 Mar 2024 18:20:00 +0000 Subject: [PATCH 2/5] fix color timezone env var warning --- rootfs/etc/s6-overlay/startup.d/01-sanity-check | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rootfs/etc/s6-overlay/startup.d/01-sanity-check b/rootfs/etc/s6-overlay/startup.d/01-sanity-check index 274e64e..f38bc55 100755 --- a/rootfs/etc/s6-overlay/startup.d/01-sanity-check +++ b/rootfs/etc/s6-overlay/startup.d/01-sanity-check @@ -25,7 +25,7 @@ fi # Set up timezone if [ -z "${TZ}" ]; then - echo "${YELLOW}WARNING: TZ environment variable not set${NOCOLOR}" + echo -e "${YELLOW}WARNING: TZ environment variable not set${NOCOLOR}" else ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime && echo "$TZ" >/etc/timezone fi From 1d95e2829aecd5f8a7deb82bd04e653aac364a21 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Wed, 20 Mar 2024 18:20:45 +0000 Subject: [PATCH 3/5] startup.d: don't prepend the whole path, just the script name --- rootfs/etc/s6-overlay/scripts/startup | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rootfs/etc/s6-overlay/scripts/startup b/rootfs/etc/s6-overlay/scripts/startup index c746be0..b783d97 100755 --- a/rootfs/etc/s6-overlay/scripts/startup +++ b/rootfs/etc/s6-overlay/scripts/startup @@ -10,9 +10,11 @@ if ! [[ -d "$SDIR" ]] || [[ -z "$(ls "$SDIR")" ]]; then exit 0 fi -for NAME in "$SDIR"/*; do - if ! s6wrap --quiet --prepend="$NAME" --timestamps --args "$NAME"; then - s6wrap --quiet --prepend=startup --timestamps --args echo Error running "$NAME" +cd "$SDIR" || exit 1 + +for NAME in *; do + if ! s6wrap --quiet --prepend="$NAME" --timestamps --args "$SDIR/$NAME"; then + s6wrap --quiet --prepend=startup --timestamps --args echo Error running "$SDIR/$NAME" exit 1 fi done From 30f84d68be1bd7fd4a946ddaaca1cd937dd33573 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Wed, 20 Mar 2024 18:23:13 +0000 Subject: [PATCH 4/5] startup.d: start after legacy cont-init.d properly define startup sequence by having startup.d depend on the base bundle (s6 v3 recommended way of enforcing that ordering) --- rootfs/etc/s6-overlay/s6-rc.d/startup/dependencies.d/base | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 rootfs/etc/s6-overlay/s6-rc.d/startup/dependencies.d/base diff --git a/rootfs/etc/s6-overlay/s6-rc.d/startup/dependencies.d/base b/rootfs/etc/s6-overlay/s6-rc.d/startup/dependencies.d/base new file mode 100644 index 0000000..e69de29 From 21aa1e3a8335ed541ffe27339c0b9061d9f00157 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Wed, 20 Mar 2024 18:26:19 +0000 Subject: [PATCH 5/5] startup service: run scripts in /etc/s6-overlay/finish.d as down action --- rootfs/etc/s6-overlay/s6-rc.d/startup/down | 2 ++ rootfs/etc/s6-overlay/scripts/startup-finish | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100755 rootfs/etc/s6-overlay/s6-rc.d/startup/down create mode 100755 rootfs/etc/s6-overlay/scripts/startup-finish diff --git a/rootfs/etc/s6-overlay/s6-rc.d/startup/down b/rootfs/etc/s6-overlay/s6-rc.d/startup/down new file mode 100755 index 0000000..2f14f7f --- /dev/null +++ b/rootfs/etc/s6-overlay/s6-rc.d/startup/down @@ -0,0 +1,2 @@ +#!/bin/sh +exec /etc/s6-overlay/scripts/startup-finish diff --git a/rootfs/etc/s6-overlay/scripts/startup-finish b/rootfs/etc/s6-overlay/scripts/startup-finish new file mode 100755 index 0000000..b8410cb --- /dev/null +++ b/rootfs/etc/s6-overlay/scripts/startup-finish @@ -0,0 +1,20 @@ +#!/command/with-contenv bash +# shellcheck shell=bash disable=SC1091,SC2076 + +source /scripts/common + +SDIR=/etc/s6-overlay/finish.d + +# exit 0 for nonexistent or empty directory +if ! [[ -d "$SDIR" ]] || [[ -z "$(ls "$SDIR")" ]]; then + exit 0 +fi + +cd "$SDIR" || exit 1 + +for NAME in *; do + if ! s6wrap --quiet --prepend="$NAME" --timestamps --args "$SDIR/$NAME"; then + s6wrap --quiet --prepend=startup --timestamps --args echo Error running "$SDIR/$NAME" + exit 1 + fi +done