Restart without reboot; retrievable logs incl. mpv exit reasons

Two related gaps on the headless kiosk: no way to restart the wall short
of a full reboot, and no way to see why a stream keeps flapping (the
daemon's stderr goes to sway on tty1, and mpv's stderr was discarded).

Restart in place:
- `rtsp-streamer restart` sends a control-socket command; the daemon
  tears down its mpv children and syscall.Exec's the on-disk binary.
  Same PID, same parent (sway), same env — keeps WAYLAND_DISPLAY/
  SWAYSOCK and comes back up on the new binary, no reboot. Handles the
  os.Executable() "(deleted)" sentinel from make install's rename.
- sway config now launches the daemon in a relaunch loop, so a crash (or
  the restart) auto-recovers instead of leaving a black screen.
- `make deploy` now does `install` + `restart` instead of restarting
  getty@tty1 (which left stale duplicate sessions and forced reboots).

Retrievable logs:
- New internal/logbuf ring; the daemon tees slog output into it and
  serves the tail over the socket via `rtsp-streamer logs [-n N]` —
  readable over SSH, no file wrangling, no reboot.
- Capture the tail of each mpv's stderr and log its last line when the
  process exits, so "mpv exited, will restart" now carries the reason
  (connection refused, unsupported codec, 401, ...). This is the
  diagnostic for a single tile going unhealthy repeatedly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Levi Woodard
2026-07-02 10:03:25 -05:00
parent 9985a93851
commit be1b53ae04
10 changed files with 308 additions and 33 deletions

View File

@@ -144,6 +144,9 @@ rtsp-streamer status # slot health from the running daemon
rtsp-streamer layout ls # list layouts (* marks active)
rtsp-streamer layout set quad # switch live (persists the choice)
rtsp-streamer reload # apply hand-edits to the config live
rtsp-streamer restart # re-exec the daemon in place (picks up a new
# binary; no reboot)
rtsp-streamer logs -n 80 # recent daemon activity incl. mpv exit reasons
rtsp-streamer version # baked-in git commit / build date
```
@@ -207,14 +210,21 @@ Then `sudo reboot` and the wall comes up on boot.
### Updating
```sh
git pull && make install && sudo reboot
git pull && make deploy
```
`make install` builds natively and copies to `/usr/local/bin` (auto-sudo — run
it *without* `sudo` so `go build` keeps your `PATH`). Use **`sudo reboot`**, not
`systemctl restart getty@tty1`: a getty restart tends to leave the old sway +
daemon running alongside the new one (duplicate mpv, windows fighting). Confirm
what's live with `rtsp-streamer version`.
`make deploy` builds natively, copies to `/usr/local/bin` (auto-sudo — run it
*without* `sudo` so `go build` keeps your `PATH`), then runs
`rtsp-streamer restart`, which tells the running daemon to **re-exec itself in
place**: same process, same sway session, now running the new binary — no
reboot, no duplicate sessions. Confirm what's live with `rtsp-streamer version`.
`restart` works because the daemon is launched under a small relaunch loop in
the sway config, so it also recovers on its own if it ever crashes. (Older
installs that predate this launcher need their sway config refreshed — re-run
`deploy/install.sh` or copy `deploy/sway/config` to
`/etc/rtsp-streamer/sway/config` once, then reboot.) A full `sudo reboot` is
still fine and never wrong.
## Enabling RTSP in UniFi Protect
@@ -262,6 +272,12 @@ pegged, work through:
## Troubleshooting
- **A stream keeps going unhealthy / flapping** — `rtsp-streamer logs` shows the
daemon's recent activity, including the *reason* each mpv exited (its stderr
tail: connection refused, unsupported codec, 401, etc.). This is the first
thing to check when one tile restarts repeatedly. A camera whose `video-codec`
is `hevc` can't hardware-decode on a Pi 4 and often stutters/exits under load —
switch it to H.264 in Protect or give the tile the `low` substream.
- **`status` can't reach the daemon** (`control.sock: no such file`) — the wall
is running as a *different user* than your SSH session (check
`ps -o user= -p "$(pgrep -x sway)"` vs `id`). Re-run `install.sh <your-user>`
@@ -306,7 +322,7 @@ pegged, work through:
## Layout
```
cmd/rtsp-streamer/ CLI (cobra): daemon, discover, layout, reload, status, tui, config, version
cmd/rtsp-streamer/ CLI (cobra): daemon, discover, layout, reload, restart, logs, status, tui, config, version
internal/config/ YAML load/save/validate, schema (tiles, streams), XDG paths
internal/protect/ UniFi Protect client (login, bootstrap, enable RTSP, URLs)
internal/player/ one supervised mpv per stream, JSON IPC, restart/backoff