ops: appliance boot — wait for cameras/LiveKit, power button powers off

This commit is contained in:
Hermes
2026-08-28 05:45:11 +00:00
parent b5a2fe6440
commit abeea6256c
7 changed files with 103 additions and 10 deletions
+9
View File
@@ -0,0 +1,9 @@
[Login]
HandlePowerKey=poweroff
HandlePowerKeyLongPress=poweroff
HandleSuspendKey=ignore
HandleHibernateKey=ignore
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore
HandleLidSwitchDocked=ignore
IdleAction=ignore
+12 -4
View File
@@ -1,20 +1,28 @@
[Unit]
Description=Publish C920 cameras (speechbrain audio) to LiveKit
Documentation=file:///home/fdenkena/livekit-cameras/README.md
After=network-online.target sound.target livekit-server.service
Wants=network-online.target
Requires=livekit-server.service
# Wants, not Requires: local livekit-server is a test stand-in.
# Point LIVEKIT_URL at a remote server later and you can disable this unit.
Wants=livekit-server.service
[Service]
Type=simple
WorkingDirectory=/home/fdenkena/livekit-cameras
EnvironmentFile=-/home/fdenkena/livekit-cameras/.env
Environment=PYTHONUNBUFFERED=1
Environment=ENHANCE_MODE=force
ExecStartPre=/home/fdenkena/livekit-cameras/deploy/wait-for-cameras.sh
ExecStartPre=/home/fdenkena/livekit-cameras/deploy/wait-for-livekit.sh
ExecStart=/home/fdenkena/livekit-cameras/.venv/bin/python /home/fdenkena/livekit-cameras/run.py
ExecStop=/bin/kill -TERM $MAINPID
Restart=always
RestartSec=5
TimeoutStartSec=90
TimeoutStopSec=30
KillMode=control-group
Environment=PYTHONUNBUFFERED=1
Environment=LIVEKIT_URL=ws://127.0.0.1:7880
Environment=ENHANCE_MODE=force
KillSignal=SIGTERM
[Install]
WantedBy=multi-user.target
+2 -1
View File
@@ -1,5 +1,6 @@
[Unit]
Description=LiveKit server for the C920 camera fleet
Description=LiveKit TEST server for the C920 camera fleet (local only)
Documentation=file:///home/fdenkena/livekit-cameras/README.md
After=network-online.target
Wants=network-online.target
+17
View File
@@ -0,0 +1,17 @@
#!/bin/bash
# Wait for udev to pin C920 nodes after boot. Never fail the unit:
# discovery can still run with whatever is present.
set -u
udevadm settle -t 20 || true
udevadm trigger --subsystem-match=video4linux --action=add || true
udevadm trigger --subsystem-match=sound --action=add || true
for _ in $(seq 1 45); do
n=$(ls -1 /dev/cam[0-9][0-9] 2>/dev/null | wc -l)
if [ "$n" -ge 1 ]; then
echo "wait-for-cameras: $n pinned /dev/camNN nodes"
exit 0
fi
sleep 1
done
echo "wait-for-cameras: none yet; starting anyway" >&2
exit 0
+39
View File
@@ -0,0 +1,39 @@
#!/bin/bash
# Wait until LIVEKIT_URL (from .env) accepts TCP. Used so publishers do not
# race the local test livekit-server on boot. When LIVEKIT_URL points at a
# remote host this waits on that host instead.
set -u
ENV_FILE=/home/fdenkena/livekit-cameras/.env
if [ -f "$ENV_FILE" ]; then
set -a
# shellcheck disable=SC1090
. "$ENV_FILE"
set +a
fi
URL="${LIVEKIT_URL:-ws://127.0.0.1:7880}"
rest="${URL#*://}"
hostport="${rest%%/*}"
host="${hostport%%:*}"
port="${hostport##*:}"
case "$hostport" in
*:*) ;;
*)
case "$URL" in
wss://*) port=443 ;;
*) port=80 ;;
esac
;;
esac
if [ "$host" = "localhost" ]; then
host=127.0.0.1
fi
echo "wait-for-livekit: $host:$port"
for _ in $(seq 1 30); do
if (echo >/dev/tcp/"$host"/"$port") 2>/dev/null; then
echo "wait-for-livekit: ready"
exit 0
fi
sleep 1
done
echo "wait-for-livekit: $host:$port not reachable after 30s" >&2
exit 1