From 2a15702bc8761ae7e0cdbf30ed180f96a8607023 Mon Sep 17 00:00:00 2001 From: Adam Dinwoodie Date: Wed, 2 Oct 2024 19:27:19 +0100 Subject: [PATCH] nixos/openvpn: don't fail to restart stopped units The current OpenVPN restart-after-sleep script will return a non-zero exit code if the system resumes from sleep and there are no active OpenVPN units, resulting in systemd reporting the system as degraded. Avoid that by only attempting to restart OpenVPN programs that are actually running at the time. This also means that any user-managed OpenVPN sessions won't be affected by NixOS's OpenVPN handling. --- nixos/modules/services/networking/openvpn.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nixos/modules/services/networking/openvpn.nix b/nixos/modules/services/networking/openvpn.nix index fba6d5e48f92..56b1f6f5ab8f 100644 --- a/nixos/modules/services/networking/openvpn.nix +++ b/nixos/modules/services/networking/openvpn.nix @@ -73,8 +73,9 @@ let openvpn-restart = { wantedBy = [ "sleep.target" ]; path = [ pkgs.procps ]; - script = "pkill --signal SIGHUP --exact openvpn"; - #SIGHUP makes openvpn process to self-exit and then it got restarted by systemd because of Restart=always + script = let + unitNames = map (n: "openvpn-${n}.service") (builtins.attrNames cfg.servers); + in "systemctl try-restart ${lib.escapeShellArgs unitNames}"; description = "Sends a signal to OpenVPN process to trigger a restart after return from sleep"; }; };