diff --git a/files/initrd/opt/arc/arc-functions.sh b/files/initrd/opt/arc/arc-functions.sh index b3776d4f..5b468876 100755 --- a/files/initrd/opt/arc/arc-functions.sh +++ b/files/initrd/opt/arc/arc-functions.sh @@ -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 diff --git a/files/initrd/opt/arc/init.sh b/files/initrd/opt/arc/init.sh index 2dbe74fe..10e6081e 100755 --- a/files/initrd/opt/arc/init.sh +++ b/files/initrd/opt/arc/init.sh @@ -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 diff --git a/scripts/functions.sh b/scripts/functions.sh index d2aa2fff..883647d9 100755 --- a/scripts/functions.sh +++ b/scripts/functions.sh @@ -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() {