#!/bin/bash # Watchdog: restart k3s if flannel.1 interface is missing. # Runs via systemd timer every 60s. # Only act if k3s is running but flannel.1 is gone K3S_UNIT=$(systemctl is-active k3s 2>/dev/null) K3S_AGENT_UNIT=$(systemctl is-active k3s-agent 2>/dev/null) if [ "$K3S_UNIT" != "active" ] && [ "$K3S_AGENT_UNIT" != "active" ]; then exit 0 # k3s isn't running, nothing to do fi if ip link show flannel.1 >/dev/null 2>&1; then exit 0 # flannel is fine fi # flannel.1 is missing — restart the appropriate service echo "$(date): flannel.1 missing, restarting k3s" logger -t k3s-watchdog "flannel.1 interface missing — restarting k3s" if [ "$K3S_UNIT" = "active" ]; then systemctl restart k3s elif [ "$K3S_AGENT_UNIT" = "active" ]; then systemctl restart k3s-agent fi