Author: eelco
Date: Mon Feb 20 15:19:46 2012
New Revision: 32430
URL: https://nixos.org/websvn/nix/?rev=32430&sc=1

Log:
* dhcpcd: restart ntpd and emit ip-up/ip-down events.  Also attach the
  interface name to the events, as suggested by Mathijs Kwik.

Modified:
   nixos/trunk/modules/services/networking/dhcpcd.nix

Modified: nixos/trunk/modules/services/networking/dhcpcd.nix
==============================================================================
--- nixos/trunk/modules/services/networking/dhcpcd.nix  Mon Feb 20 15:12:34 
2012        (r32429)
+++ nixos/trunk/modules/services/networking/dhcpcd.nix  Mon Feb 20 15:19:46 
2012        (r32430)
@@ -35,6 +35,29 @@
       denyinterfaces ${toString ignoredInterfaces} peth* vif* tap* virbr* vnet*
     '';
 
+  # Hook for emitting ip-up/ip-down events.
+  exitHook = pkgs.writeText "dhcpcd.exit-hook"
+    ''
+      #exec >> /var/log/dhcpcd 2>&1
+      #set -x
+    
+      if [ "$reason" = BOUND -o "$reason" = REBOOT ]; then
+          # Restart ntpd.  (The "ip-up" event below will trigger the
+          # restart.)  We need to restart it to make sure that it will
+          # actually do something: if ntpd cannot resolve the server
+          # hostnames in its config file, then it will never do
+          # anything ever again ("couldn't resolve ..., giving up on
+          # it"), so we silently lose time synchronisation.
+          ${config.system.build.upstart}/sbin/initctl stop ntpd
+
+          ${config.system.build.upstart}/sbin/initctl emit -n ip-up 
IFACE=$interface
+      fi
+
+      if [ "$reason" = EXPIRE -o "$reason" = RELEASE ]; then
+          ${config.system.build.upstart}/sbin/initctl emit -n ip-down 
IFACE=$interface
+      fi
+    '';
+
 in
 
 {
@@ -49,13 +72,17 @@
 
         path = [ dhcpcd pkgs.nettools pkgs.openresolv ];
 
-        exec = "dhcpcd --config ${dhcpcdConf} --background --persistent";
-
-        daemonType = "daemon";
+        exec = "dhcpcd --config ${dhcpcdConf} --nobackground --persistent";
       };
 
     environment.systemPackages = [ dhcpcd ];
 
+    environment.etc =
+      [ { source = exitHook;
+          target = "dhcpcd.exit-hook";
+        }
+      ];
+
     powerManagement.resumeCommands =
       ''
         ${config.system.build.upstart}/sbin/restart dhcpcd
_______________________________________________
nix-commits mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-commits

Reply via email to