Skip to content

Instantly share code, notes, and snippets.

@Airyzz
Created February 3, 2026 14:53
Show Gist options
  • Select an option

  • Save Airyzz/ea7b6f59840d3f2033f2b3040f2b7d68 to your computer and use it in GitHub Desktop.

Select an option

Save Airyzz/ea7b6f59840d3f2033f2b3040f2b7d68 to your computer and use it in GitHub Desktop.
restart livekit when public ip changes, for DDNS setups
#!/usr/bin/env bash
POLL_INTERVAL=600 # seconds
LAST_IP=""
on_ip_change() {
local old_ip="$1"
local new_ip="$2"
echo "$(date '+%Y-%m-%d %H:%M:%S') IP CHANGED: $old_ip -> $new_ip"
docker restart livekit
}
while true; do
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
CURRENT_IP=$(curl -s --max-time 5 ifconfig.io)
if [[ -z "$CURRENT_IP" ]]; then
echo "$TIMESTAMP request failed (empty response)"
elif [[ ! "$CURRENT_IP" =~ ^[0-9a-fA-F:.]+$ ]]; then
echo "$TIMESTAMP invalid response: $CURRENT_IP"
else
echo "$TIMESTAMP current IP: $CURRENT_IP"
if [[ "$CURRENT_IP" != "$LAST_IP" ]]; then
if [[ -n "$LAST_IP" ]]; then
on_ip_change "$LAST_IP" "$CURRENT_IP"
fi
LAST_IP="$CURRENT_IP"
fi
fi
sleep "$POLL_INTERVAL"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment