webui: recover from a stale thttpd pidfile

thttpd does not remove its pidfile when it dies, so a crash left the
file behind pointing at a dead pid. The boot guard only tested that the
file existed, concluded the server was up and skipped the restart, so
nothing was listening while the loader carried on and reported an ip.
That is the connection refused on a running system. Test the pid with
kill -0 instead and clear the file before restarting.

The shipped init script had no monitor loop to catch this later, and its
stop() bailed out with FAIL when the pidfile was missing, so restart
could not recover a thttpd that was running without one. Fall back to
killall in that case, and never signal a recorded pid that is no longer
alive since the number may have been recycled.

loaderPorts compared the new port against HTTPPORT, which arc.conf had
already been rewritten to hold, so the restart was skipped on a real
change. Capture the running port before the rewrite.
This commit is contained in:
AuxXxilium
2026-08-11 20:59:12 +02:00
parent 2c7bd64d76
commit 0005cf4804
3 changed files with 15 additions and 7 deletions

View File

@@ -2404,6 +2404,8 @@ function loaderPorts() {
unset HTTPPORT
[ -f "/etc/arc.conf" ] && source "/etc/arc.conf" 2>/dev/null
local HTTP=${HTTPPORT:-7080}
# Remember the running port, arc.conf gets rewritten below
local HTTPOLD=${HTTPPORT:-7080}
while true; do
dialog --backtitle "$(backtitle)" --title "Loader Ports" \
--form "${MSG}" 9 70 1 "HTTP" 1 1 "${HTTPPORT:-7080}" 1 10 55 0 \
@@ -2471,7 +2473,7 @@ function loaderPorts() {
[ ! -f "/etc/arc.conf" ] && MSG="HTTP Port restored." || MSG="HTTP Port changed."
dialog --backtitle "$(backtitle)" --title "Loader Ports" \
--msgbox "${MSG}" 0 0
if [ ! "${HTTP:-7080}" = "${HTTPPORT:-7080}" ]; then
if [ ! "${HTTP:-7080}" = "${HTTPOLD}" ]; then
/etc/init.d/S90thttpd restart
fi
break

View File

@@ -215,7 +215,11 @@ RESTARTED=0
if [ ! -f "/.dockerenv" ]; then
[ ! -f /var/run/dhcpcd/pid ] && /etc/init.d/S41dhcpcd restart >/dev/null 2>&1 && RESTARTED=1
fi
[ ! -f /var/run/thttpd.pid ] && /etc/init.d/S90thttpd restart >/dev/null 2>&1 && RESTARTED=1
# thttpd leaves its pidfile behind when it dies, so check the process, not the file
if [ ! -f /var/run/thttpd.pid ] || ! kill -0 "$(cat /var/run/thttpd.pid 2>/dev/null)" 2>/dev/null; then
rm -f /var/run/thttpd.pid
/etc/init.d/S90thttpd restart >/dev/null 2>&1 && RESTARTED=1
fi
[ "${RESTARTED}" = "1" ] && sleep 5
IPCON=""
checkNIC

View File

@@ -337,13 +337,15 @@ start() {
stop() {
printf 'Stopping %s: ' "$DAEMON"
if [ -f "$PIDFILE" ]; then
kill $(cat "$PIDFILE") 2>/dev/null
rm -f "$PIDFILE"
echo "OK"
# Only signal the recorded pid if it is still ours, the pid file outlives a
# crashed thttpd and the number may have been recycled by then
if [ -f "$PIDFILE" ] && kill -0 "$(cat "$PIDFILE" 2>/dev/null)" 2>/dev/null; then
kill "$(cat "$PIDFILE")" 2>/dev/null
else
echo "FAIL"
killall "$DAEMON" 2>/dev/null
fi
rm -f "$PIDFILE"
echo "OK"
}
restart() {