Files
RTSP-Streamer/Makefile
Levi Woodard be1b53ae04 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>
2026-07-02 10:03:25 -05:00

71 lines
2.2 KiB
Makefile

BINARY := rtsp-streamer
PKG := ./cmd/rtsp-streamer
BINDIR := bin
# Build metadata baked into the binary (see `rtsp-streamer version`).
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo dev)
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || echo none)
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS := -s -w \
-X main.version=$(VERSION) \
-X main.commit=$(COMMIT) \
-X main.date=$(DATE)
# Install location. Override with `make install PREFIX=/opt`.
PREFIX ?= /usr/local
DESTBIN := $(PREFIX)/bin/$(BINARY)
# Use sudo automatically when not already root, so `make install` /
# `make deploy` work whether or not you prefix them with sudo.
SUDO := $(shell [ "$$(id -u)" -eq 0 ] || echo sudo)
.PHONY: all build pi pi32 test vet clean run-tui install deploy uninstall
all: build
## build: compile for the host platform (native arch)
build:
go build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(BINARY) $(PKG)
## pi: cross-compile for Raspberry Pi 4 running a 64-bit OS (arm64)
pi:
GOOS=linux GOARCH=arm64 go build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(BINARY)-arm64 $(PKG)
## pi32: cross-compile for a 32-bit Pi OS (armv7)
pi32:
GOOS=linux GOARCH=arm GOARM=7 go build -ldflags '$(LDFLAGS)' -o $(BINDIR)/$(BINARY)-armv7 $(PKG)
## install: build for this machine and copy the binary to $(PREFIX)/bin
## (auto-sudo). This is the location the running daemon uses.
install: build
$(SUDO) install -m 0755 $(BINDIR)/$(BINARY) $(DESTBIN)
@echo "installed -> $(DESTBIN)"
## deploy: install, then restart the running wall in place (no reboot). Run as
## the kiosk user so it reaches the daemon's control socket. Falls back to a
## note if the daemon isn't up yet (it will start on next boot).
deploy: install
@$(DESTBIN) restart || echo "daemon not running; it will start on next boot"
@echo "run 'rtsp-streamer status' to check"
## uninstall: remove the installed binary
uninstall:
$(SUDO) rm -f $(DESTBIN)
@echo "removed $(DESTBIN)"
## test: run unit tests
test:
go test ./...
## vet: run go vet
vet:
go vet ./...
## run-tui: launch the configurator against a scratch config
run-tui: build
RTSP_STREAMER_CONFIG=/tmp/rtsp-streamer.yaml $(BINDIR)/$(BINARY) tui
## clean: remove build artifacts
clean:
rm -rf $(BINDIR)