idk a bunch more updates
This commit is contained in:
@@ -50,5 +50,40 @@ in
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
# Ensure WireGuard restarts on failure
|
||||
systemd.services.wireguard-wg0 = {
|
||||
serviceConfig = {
|
||||
Restart = "on-failure";
|
||||
RestartSec = "5s";
|
||||
};
|
||||
};
|
||||
|
||||
# Periodic connection health check and reconnect
|
||||
systemd.services.wireguard-wg0-healthcheck = {
|
||||
description = "WireGuard wg0 connection health check";
|
||||
after = [ "network-online.target" "wireguard-wg0.service" ];
|
||||
wants = [ "network-online.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = pkgs.writeShellScript "wg0-healthcheck" ''
|
||||
# Check if we can ping the WireGuard gateway
|
||||
if ! ${pkgs.iputils}/bin/ping -c 1 -W 5 10.0.69.1 &>/dev/null; then
|
||||
echo "WireGuard connection down, restarting..."
|
||||
${pkgs.systemd}/bin/systemctl restart wireguard-wg0.service
|
||||
fi
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.wireguard-wg0-healthcheck = {
|
||||
description = "Timer for WireGuard wg0 health check";
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnBootSec = "2min";
|
||||
OnUnitActiveSec = "2min";
|
||||
Unit = "wireguard-wg0-healthcheck.service";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user