From 23297b0edde896f76ca1392d45e3c27b1422bafe Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 24 Apr 2014 23:15:39 +0200 Subject: [PATCH] Make nscd startup synchronous Nscd forks into the background before it's ready to accept connections. So explicitly wait until it's ready. http://hydra.nixos.org/build/10661767 --- nixos/modules/services/system/nscd.nix | 13 ++++++++++++- nixos/tests/misc.nix | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/nixos/modules/services/system/nscd.nix b/nixos/modules/services/system/nscd.nix index f357eb4e1fc8..1ac82064a1f7 100644 --- a/nixos/modules/services/system/nscd.nix +++ b/nixos/modules/services/system/nscd.nix @@ -9,6 +9,8 @@ let inherit (pkgs.lib) singleton; + cfgFile = pkgs.writeText "nscd.conf" cfg.config; + in { @@ -63,7 +65,7 @@ in restartTriggers = [ config.environment.etc.hosts.source ]; serviceConfig = - { ExecStart = "@${pkgs.glibc}/sbin/nscd nscd -f ${pkgs.writeText "nscd.conf" cfg.config}"; + { ExecStart = "@${pkgs.glibc}/sbin/nscd nscd -f ${cfgFile}"; Type = "forking"; PIDFile = "/run/nscd/nscd.pid"; Restart = "always"; @@ -73,6 +75,15 @@ in "${pkgs.glibc}/sbin/nscd --invalidate hosts" ]; }; + + # Urgggggh... Nscd forks before opening its socket and writing + # its pid. So wait until it's ready. + postStart = + '' + while ! ${pkgs.glibc}/sbin/nscd -g -f ${cfgFile} > /dev/null; do + sleep 0.2 + done + ''; }; }; diff --git a/nixos/tests/misc.nix b/nixos/tests/misc.nix index 031fff2de585..24c8b230629c 100644 --- a/nixos/tests/misc.nix +++ b/nixos/tests/misc.nix @@ -13,6 +13,8 @@ import ./make-test.nix { testScript = '' + $machine->waitForUnit("default.target"); + subtest "nixos-version", sub { $machine->succeed("[ `nixos-version | wc -w` = 2 ]"); }; @@ -61,8 +63,6 @@ import ./make-test.nix { # Test whether hostname (and by extension nss_myhostname) works. subtest "hostname", sub { - $machine->waitForUnit("dhcpcd.service"); - $machine->waitForUnit("network.target"); $machine->succeed('[ "`hostname`" = machine ]'); $machine->succeed('[ "`hostname -s`" = machine ]'); };