diff --git a/board/common/rootfs/etc/finit.d/available/ttyd.conf b/board/common/rootfs/etc/finit.d/available/ttyd.conf index 58205b2f..8c36d515 100644 --- a/board/common/rootfs/etc/finit.d/available/ttyd.conf +++ b/board/common/rootfs/etc/finit.d/available/ttyd.conf @@ -1 +1 @@ -service [2345] ttyd -i lo -p 8001 login -- Web terminal daemon (ttyd) +service [2345] ttyd -i lo -W -p 8001 login -- Web terminal daemon (ttyd) diff --git a/board/common/rootfs/usr/sbin/container b/board/common/rootfs/usr/sbin/container index 7905b712..5561729c 100755 --- a/board/common/rootfs/usr/sbin/container +++ b/board/common/rootfs/usr/sbin/container @@ -39,6 +39,11 @@ err() [ "$rc" -eq 0 ] || exit "$rc" } +pidfn() +{ + echo "/run/containers/${1}.pid" +} + check() { file=$1 @@ -235,7 +240,7 @@ create() args="$args --read-only --replace --quiet --cgroup-parent=containers $caps" args="$args --restart=$restart --systemd=false --tz=local $privileged" args="$args $vol $mount $hostname $entrypoint $env $port $logging" - pidfn=/run/container:${name}.pid + pidfile=/run/container:${name}.pid [ -n "$quiet" ] || log "---------------------------------------" [ -n "$quiet" ] || log "Got name: $name image: $image" @@ -258,8 +263,8 @@ create() fi # shellcheck disable=SC2048 - log "podman create --name $name --conmon-pidfile=$pidfn $args $image $*" - if podman create --name "$name" --conmon-pidfile="$pidfn" $args "$image" $*; then + log "podman create --name $name --conmon-pidfile=$pidfile $args $image $*" + if podman create --name "$name" --conmon-pidfile="$pidfile" $args "$image" $*; then [ -n "$quiet" ] || log "Successfully created container $name from $image" [ -n "$manual" ] || start "$name" @@ -340,6 +345,24 @@ wrap() { name=$1 cmd=$2 + pidfile=$(pidfn "$name") + + # Containers have three phases: setup, running, and teardown. + + # The setup phase may run forever in the background trying to fetch + # the image. It saves its PID in /run/containers/${name}.pid + if [ "$cmd" = "stop" ] && [ -f "$pidfile" ]; then + pid=$(cat "$pidfile") + + # Check if setup is still running ... + if kill -0 "$pid" 2>/dev/null; then + kill "$pid" + wait "$pid" 2>/dev/null + fi + + rm -f "$pidfile" + return 0 + fi # Skip "echo $name" from podman start in log podman "$cmd" "$name" >/dev/null @@ -375,7 +398,14 @@ netrestart() cleanup() { + pidfile=$(pidfn "$name") + log "Received signal, exiting." + if [ -n "$name" ] && [ -f "$pidfile" ]; then + log "$name: in setup phase, removing $pidfile ..." + rm -f "$pidfile" + fi + exit 1 } @@ -574,7 +604,7 @@ if [ -n "$cmd" ]; then shift fi -trap cleanup INT TERM +trap cleanup INT HUP TERM case $cmd in # Does not work atm., cannot attach to TTY because @@ -710,6 +740,12 @@ case $cmd in [ -n "$name" ] || err 1 "setup: missing container name." script=/run/containers/${name}.sh [ -x "$script" ] || err 1 "setup: $script does not exist or is not executable." + + # Save our PID in case we get stuck here and someone wants to + # stop us, e.g., due to reconfiguration or reboot. + pidfile=$(pidfn "${name}") + echo $$ > "$pidfile" + while ! "$script"; do log "${name}: setup failed, waiting for network changes ..." read -t 60 _ < <(ip monitor address route) @@ -719,6 +755,8 @@ case $cmd in log "${name}: retrying ..." sleep 2 done + + rm -f "$pidfile" ;; shell) if [ -z "$name" ]; then diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index a15db37b..b7c1280d 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -6,7 +6,9 @@ All notable changes to the project are documented in this file. [v25.03.0][UNRELEASED] - ------------------------- -**News:** this release is the first with the new Buildroot LTS (2025.02) + +> [!IMPORTANT] +> This release is the first with the new Buildroot 2025.02 (LTS) ### Changes - Upgrade Linux kernel to 6.12.21 (LTS) @@ -14,6 +16,10 @@ All notable changes to the project are documented in this file. ### Fixes - Fix #964: YANG schema warning in syslog: missing 'monitor' node for lag + - Fix #980: the system fails to reboot when a container is (stuck), for + whatever reason, in its 'setup' state + - Fix #990: web console, ttyd service, stopped working after upgrade to + Buildroot 2025.02, caused by new (missing) option `--writable` [v25.02.0][] - 2025-03-04 diff --git a/package/finit/finit.hash b/package/finit/finit.hash index 8c6130ce..c9a94f26 100644 --- a/package/finit/finit.hash +++ b/package/finit/finit.hash @@ -1,5 +1,5 @@ # From https://github.com/troglobit/finit/releases/ -sha256 da14f5f05f595e15abc73bbacabfb55e8e1a4c40fc6ca6ab294be34ea437cc82 finit-4.10.tar.gz +sha256 7e49a3df58c5aedfff9537b7ff34b9238fc28b523d4dbacc316d606c7af5e335 finit-4.11.tar.gz # Locally calculated sha256 2fd62c0fe6ea6d1861669f4c87bda83a0b5ceca64f4baa4d16dd078fbd218c14 LICENSE diff --git a/package/finit/finit.mk b/package/finit/finit.mk index e3060497..96108029 100644 --- a/package/finit/finit.mk +++ b/package/finit/finit.mk @@ -4,7 +4,7 @@ # ################################################################################ -FINIT_VERSION = 4.10 +FINIT_VERSION = 4.11 FINIT_SITE = https://github.com/troglobit/finit/releases/download/$(FINIT_VERSION) FINIT_LICENSE = MIT FINIT_LICENSE_FILES = LICENSE