summaryrefslogtreecommitdiff
path: root/pkgs/lib/services/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/lib/services/default.nix')
-rw-r--r--pkgs/lib/services/default.nix29
1 files changed, 8 insertions, 21 deletions
diff --git a/pkgs/lib/services/default.nix b/pkgs/lib/services/default.nix
index 148126c..0363ecc 100644
--- a/pkgs/lib/services/default.nix
+++ b/pkgs/lib/services/default.nix
@@ -8,7 +8,12 @@ let
name = "check-network";
runtimeInputs = [ pkgs.unixtools.ping ];
text = ''
- (${lib.concatMapStringsSep " && " (host: "ping -c 1 ${host}") hosts}) || kill -s SIGUSR1 $$
+ for _ in {1..5}
+ do
+ (${lib.concatMapStringsSep " && " (host: "ping -c 1 ${host}") hosts}) && exit 0
+ sleep 30
+ done
+ exit 1
'';
};
in
@@ -37,42 +42,24 @@ in
home.checkNetwork =
{
hosts,
- restart ? true,
+ ...
}:
{
# Check network connectivity
- Unit = {
- StartLimitIntervalSec = 300;
- StartLimitBurst = 5;
- };
Service = lib.mkMerge [
{
ExecStartPre = checkNetwork hosts;
}
- (lib.mkIf restart {
- Restart = "on-abort";
- RestartSec = 30;
- RestartMode = "direct"; # dependent units will not fail
- })
];
};
checkNetwork =
{
hosts,
- restart ? true,
+ ...
}:
{
# Check network connectivity
preStart = checkNetwork hosts;
- unitConfig = {
- StartLimitIntervalSec = 300;
- StartLimitBurst = 5;
- };
- serviceConfig = lib.mkIf restart {
- Restart = "on-abort";
- RestartSec = 30;
- RestartMode = "direct"; # dependent units will not fail
- };
};
}