#!/bin/bash # Wait for wg0 interface to be up with an IP before allowing k3s to start. # Used as ExecStartPre in k3s systemd drop-in. MAX_WAIT=120 INTERVAL=2 ELAPSED=0 while [ $ELAPSED -lt $MAX_WAIT ]; do if ip link show wg0 >/dev/null 2>&1 && ip addr show wg0 | grep -q 'inet '; then echo "wg0 is up with IP after ${ELAPSED}s" exit 0 fi sleep $INTERVAL ELAPSED=$((ELAPSED + INTERVAL)) done echo "ERROR: wg0 not up after ${MAX_WAIT}s — starting k3s anyway" exit 0 # don't block k3s forever, let the watchdog handle it