From 17bbf35907973c438cc50956d054abbeda106a11 Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Wed, 11 May 2022 14:23:27 +0000 Subject: [PATCH] OpenVPN keep-alive service --- networking.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/networking.nix b/networking.nix index c6e311b..0c1c63a 100644 --- a/networking.nix +++ b/networking.nix @@ -100,6 +100,18 @@ in { wantedBy = [ "suspend.target" "hibernate.target" "hybrid-sleep.target" ]; script = "${pkgs.systemd}/bin/systemctl try-restart openvpn-vpn.service"; }; + "openvpn-keep-alive" = { + description = "Make sure OpenVPN connection is alive"; + after = [ "openvpn-vpn.service" ]; + wantedBy = [ "openvpn-vpn.service" ]; + script = '' + while [ 1 ]; do + sleep 10s + timeout 10s ${pkgs.iputils}/bin/ping -c1 1.1.1.1 >/dev/null 2>&1 || \ + ${pkgs.systemd}/bin/systemctl try-restart openvpn-vpn.service + done + ''; + }; }; }; }