nixos/openvpn: added restartAfterSleep option

Additional systemd unit that hooks to sleep.target and kills openvpn processes
This commit is contained in:
gbtb
2022-12-12 23:37:57 +10:00
parent 95f1ec7216
commit 3d17d6fff6
+18 -1
View File
@@ -70,6 +70,16 @@ let
serviceConfig.Type = "notify";
};
restartService = optionalAttrs cfg.restartAfterSleep {
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
description = "Sends a signal to OpenVPN process to trigger a restart after return from sleep";
};
};
in
{
@@ -201,6 +211,12 @@ in
};
services.openvpn.restartAfterSleep = mkOption {
default = true;
type = types.bool;
description = lib.mdDoc "Whether OpenVPN clients should be restarted after sleep.";
};
};
@@ -208,7 +224,8 @@ in
config = mkIf (cfg.servers != {}) {
systemd.services = listToAttrs (mapAttrsFlatten (name: value: nameValuePair "openvpn-${name}" (makeOpenVPNJob value name)) cfg.servers);
systemd.services = (listToAttrs (mapAttrsFlatten (name: value: nameValuePair "openvpn-${name}" (makeOpenVPNJob value name)) cfg.servers))
// restartService;
environment.systemPackages = [ openvpn ];