From e8e3df3163296f58098924de2feebd1d566a34a7 Mon Sep 17 00:00:00 2001 From: Adrian Fedoreanu Date: Sun, 9 Aug 2026 18:21:14 +0200 Subject: [PATCH 1/2] majestic: make S95majestic stop work when the pidfile is stale majestic's built-in watchdog respawns the process outside start-stop-daemon's knowledge, so /var/run/majestic.pid goes stale. 'stop' then kills nothing (start-stop-daemon -K targets the dead pid), and 'restart' starts a second majestic next to the surviving one - two daemons fight over the encoder and config edits appear to take effect but the running process never loaded them. Observed on a Hi3518EV200 camera: pidfile said 3408, majestic ran as 869, /etc/init.d/S95majestic restart exited 0 having restarted nothing; /api/v1/config.json confirmed the old config was still live. After the pidfile kill, verify the daemon is gone with pidof and fall back to killall (TERM, then KILL), which matches by name and cannot go stale. Always remove the pidfile so the next start begins clean. --- general/package/majestic/files/S95majestic | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/general/package/majestic/files/S95majestic b/general/package/majestic/files/S95majestic index bef48e2c41..be4ee9b990 100755 --- a/general/package/majestic/files/S95majestic +++ b/general/package/majestic/files/S95majestic @@ -14,15 +14,23 @@ start() { fi } +# Stop by pidfile, then verify the daemon is actually gone. majestic's own +# watchdog restarts it with a new pid that start-stop-daemon knows nothing +# about, so the pidfile goes stale; -K on a stale pidfile kills nothing, and +# "restart" then starts a SECOND majestic next to the running one - both +# fighting over the encoder, with config edits silently never loaded. killall +# matches by name, which is the one identity that cannot go stale. stop() { echo -n "Stopping $DAEMON: " start-stop-daemon -K -q -p "$PIDFILE" - if [ $? -eq 0 ]; then - rm -f "$PIDFILE" - echo "OK" - else - echo "FAIL" + sleep 1 + if pidof "$DAEMON" > /dev/null 2>&1; then + killall "$DAEMON" 2> /dev/null + sleep 2 + killall -9 "$DAEMON" 2> /dev/null fi + rm -f "$PIDFILE" + echo "OK" } case "$1" in From 09457013b872772ce5961e96b9528e32ad96f520 Mon Sep 17 00:00:00 2001 From: Adrian Fedoreanu Date: Sun, 9 Aug 2026 18:37:06 +0200 Subject: [PATCH 2/2] S95majestic: report stop failure instead of claiming success Review follow-up: verify the daemon is actually gone after the kill sequence. If it survives even SIGKILL, print FAIL and return non-zero, and make restart abort instead of starting a second instance next to a daemon that refused to die. The pidfile is only removed once the daemon is confirmed gone. --- general/package/majestic/files/S95majestic | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/general/package/majestic/files/S95majestic b/general/package/majestic/files/S95majestic index be4ee9b990..1de003a8b3 100755 --- a/general/package/majestic/files/S95majestic +++ b/general/package/majestic/files/S95majestic @@ -28,6 +28,11 @@ stop() { killall "$DAEMON" 2> /dev/null sleep 2 killall -9 "$DAEMON" 2> /dev/null + sleep 1 + fi + if pidof "$DAEMON" > /dev/null 2>&1; then + echo "FAIL" + return 1 fi rm -f "$PIDFILE" echo "OK" @@ -39,7 +44,7 @@ case "$1" in ;; restart) - stop + stop || exit 1 sleep 3 start ;;