Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions general/package/waybeam/files/S95waybeam
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ WATCHDOG="waybeam-wd"
DAEMON_PATH="/usr/bin/waybeam"
LOG_PATH="/tmp/waybeam.log"

# Seconds to wait for a graceful exit. waybeam's teardown releases SigmaStar
# kernel state and can legitimately take ~12s when the MI flush is slow, so
# this needs real headroom -- a short window turns a slow shutdown into a
# reported failure.
STOP_TIMEOUT_S=30

# waybeam forks a respawn child (comm "waybeam-resp") on an API restart and a
# watchdog ("waybeam-wd"). pidof and killall match by comm, so every restart
# path must cover all three names, otherwise stop() returns while a helper is
Expand All @@ -16,7 +22,7 @@ still_running() {

wait_exit() {
i=0
while [ $i -lt 30 ]; do
while [ $i -lt $((STOP_TIMEOUT_S * 2)) ]; do
still_running || return 0
sleep 0.5
i=$((i + 1))
Expand Down Expand Up @@ -49,16 +55,21 @@ stop() {
echo "OK"
return 0
fi
# 15s of SIGTERM was not enough. Escalate rather than report a stop that
# did not happen: restart would then run start() against a survivor, which
# trips the duplicate-instance check and returns 0 having done nothing --
# the requested restart silently never happens.
killall -9 "$DAEMON" "$RESPAWN" "$WATCHDOG" 2>/dev/null
if wait_exit; then
echo "OK (forced)"
return 0
fi
echo "FAILED ($DAEMON survived SIGKILL)"
# Deliberately no SIGKILL escalation. waybeam releases SigmaStar kernel
# state on its way out (MI_SYS_Exit / MI_VENC_DestroyChn); SIGKILL skips
# that and leaves the MI channel and binding slots occupied, and nothing
# in userspace can reclaim them. The next start then binds a half-open
# channel whose symptom is "no encoder data received" until the board is
# power-cycled -- a bad place for an init script to leave a camera, since
# restart is what people run when they cannot reach the hardware.
#
# Reporting the failure instead keeps the still-running instance
# streaming, and "restart) stop && start" stops a second instance from
# being started on top of wedged state. If the daemon is genuinely hung
# the SDK is already stuck, and a reboot -- which waybeam's own teardown
# watchdog performs when its MI flush wedges -- is the recovery that
# returns the board to a known state.
echo "FAILED (still running after ${STOP_TIMEOUT_S}s; not forcing, SIGKILL wedges the SigmaStar MI state)"
return 1
}

Expand Down
Loading