From 0fa3488ddeb598f66298d6df32b48d75ad90a8d9 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Mon, 18 May 2026 18:29:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Exit=20cleanly=20when=20SSH=20ac?= =?UTF-8?q?cess=20is=20disabled?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the SSH port is not exposed, the sshd service ran a `sleep 864000` placeholder. On graceful shutdown that placeholder was killed by SIGTERM, causing the finish script to set the container exit code to 143. Disable the sshd service entirely via an `S6_STAGE2_HOOK` script that removes it from the user bundle when no SSH port is configured, matching the pattern used by some official add-ons. The container now exits with 0 on a graceful shutdown. Co-Authored-By: Claude Opus 4.7 (1M context) --- ssh/Dockerfile | 4 +++- ssh/rootfs/etc/s6-overlay/s6-rc.d/sshd/run | 5 ----- ssh/rootfs/etc/s6-overlay/scripts/enable-check.sh | 13 +++++++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) create mode 100755 ssh/rootfs/etc/s6-overlay/scripts/enable-check.sh diff --git a/ssh/Dockerfile b/ssh/Dockerfile index c73597f50..a67cd7632 100644 --- a/ssh/Dockerfile +++ b/ssh/Dockerfile @@ -6,7 +6,9 @@ FROM ${BUILD_FROM} SHELL ["/bin/bash", "-o", "pipefail", "-c"] # Add env -ENV TERM="xterm-256color" +ENV \ + TERM="xterm-256color" \ + S6_STAGE2_HOOK=/etc/s6-overlay/scripts/enable-check.sh # Copy Python requirements file COPY requirements.txt /tmp/ diff --git a/ssh/rootfs/etc/s6-overlay/s6-rc.d/sshd/run b/ssh/rootfs/etc/s6-overlay/s6-rc.d/sshd/run index fe8227e46..792b39692 100755 --- a/ssh/rootfs/etc/s6-overlay/s6-rc.d/sshd/run +++ b/ssh/rootfs/etc/s6-overlay/s6-rc.d/sshd/run @@ -6,11 +6,6 @@ # ============================================================================== declare -a options -# If SSH is disabled, use a fake sleep process -if ! bashio::var.has_value "$(bashio::addon.port 22)"; then - exec sleep 864000 -fi - bashio::log.info 'Starting the SSH daemon...' # Default options diff --git a/ssh/rootfs/etc/s6-overlay/scripts/enable-check.sh b/ssh/rootfs/etc/s6-overlay/scripts/enable-check.sh new file mode 100755 index 000000000..db5d27b6b --- /dev/null +++ b/ssh/rootfs/etc/s6-overlay/scripts/enable-check.sh @@ -0,0 +1,13 @@ +#!/command/with-contenv bashio +# shellcheck shell=bash +# ============================================================================== +# Enable optional services based on the add-on configuration +# ============================================================================== + +# Disable the SSH daemon when no SSH port is exposed +if ! bashio::var.has_value "$(bashio::addon.port 22)"; then + bashio::log.info \ + "No network port is defined in the configuration so access" \ + "will only be available via the web interface." + rm -f /etc/s6-overlay/s6-rc.d/user/contents.d/sshd +fi