23 lines
812 B
Bash
23 lines
812 B
Bash
|
|
#!/bin/bash
|
||
|
|
# Checks every 5 minutes if a livekit restart is pending.
|
||
|
|
# Only restarts when there are no active WebSocket connections on port 7881
|
||
|
|
# (established connections = active call participants).
|
||
|
|
# Run by: livekit-graceful-restart.timer (systemd)
|
||
|
|
|
||
|
|
if [ ! -f /run/livekit-restart-pending ]; then
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
|
||
|
|
# Count established WebSocket signaling connections on livekit port 7881
|
||
|
|
ACTIVE=$(ss -tn state established '( dport = :7881 or sport = :7881 )' | grep -c ESTAB || true)
|
||
|
|
|
||
|
|
if [ "$ACTIVE" -gt 0 ]; then
|
||
|
|
echo "$(date): Livekit restart pending but $ACTIVE active connection(s) — waiting."
|
||
|
|
exit 0
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "$(date): No active calls — applying livekit-server restart."
|
||
|
|
systemctl restart livekit-server
|
||
|
|
rm -f /run/livekit-restart-pending
|
||
|
|
echo "$(date): livekit-server restarted successfully."
|