diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2009-05-27 23:30:29 +0000 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2009-05-27 23:30:29 +0000 |
commit | 05a08adf9176c76e9541f363081e6f33cfb55e20 (patch) | |
tree | ab056a49a9b3520ac9bf85cde33950ba99e085be /modules/services/networking/dhclient.nix | |
parent | 3c6ae39a0d810c098f503710278c46c8cd015003 (diff) | |
download | nixlib-05a08adf9176c76e9541f363081e6f33cfb55e20.tar nixlib-05a08adf9176c76e9541f363081e6f33cfb55e20.tar.gz nixlib-05a08adf9176c76e9541f363081e6f33cfb55e20.tar.bz2 nixlib-05a08adf9176c76e9541f363081e6f33cfb55e20.tar.lz nixlib-05a08adf9176c76e9541f363081e6f33cfb55e20.tar.xz nixlib-05a08adf9176c76e9541f363081e6f33cfb55e20.tar.zst nixlib-05a08adf9176c76e9541f363081e6f33cfb55e20.zip |
* Move the dhclient exit hooks file to the dhclient module, where it
belongs. svn path=/nixos/branches/modular-nixos/; revision=15755
Diffstat (limited to 'modules/services/networking/dhclient.nix')
-rw-r--r-- | modules/services/networking/dhclient.nix | 83 |
1 files changed, 53 insertions, 30 deletions
diff --git a/modules/services/networking/dhclient.nix b/modules/services/networking/dhclient.nix index 32e71f5af600..39c93860bfec 100644 --- a/modules/services/networking/dhclient.nix +++ b/modules/services/networking/dhclient.nix @@ -38,6 +38,7 @@ in ###### implementation let + ifEnable = arg: if config.networking.useDHCP then arg else if builtins.isList arg then [] @@ -51,6 +52,22 @@ let map (i: i.name) (lib.filter (i: i ? ipAddress) config.networking.interfaces); stateDir = "/var/lib/dhcp"; # Don't use /var/state/dhcp; not FHS-compliant. + + dhclientExitHooks = pkgs.writeText "dhclient-exit-hooks" + '' + echo "$reason" >> /tmp/dhcp-exit + echo "$exit_status" >> /tmp/dhcp-exit + + if test "$reason" = BOUND -o "$reason" = REBOOT; then + ${pkgs.glibc}/sbin/nscd --invalidate hosts + ${pkgs.upstart}/sbin/initctl emit ip-up + fi + + if test "$reason" = EXPIRE -o "$reason" = RELEASE; then + ${pkgs.upstart}/sbin/initctl emit ip-down + fi + ''; + in { @@ -59,44 +76,50 @@ in options ]; - services = { - extraJobs = ifEnable [{ - name = "dhclient"; + services.extraJobs = ifEnable [{ + name = "dhclient"; - extraPath = [dhcp]; - - job = " -description \"DHCP client\" + extraPath = [dhcp]; -start on network-interfaces/started -stop on network-interfaces/stop + job = '' + description "DHCP client" -env PATH_DHCLIENT_SCRIPT=${dhcp}/sbin/dhclient-script + start on network-interfaces/started + stop on network-interfaces/stop -script - export PATH=${nettools}/sbin:$PATH + env PATH_DHCLIENT_SCRIPT=${dhcp}/sbin/dhclient-script - # Determine the interface on which to start dhclient. - interfaces= + script + export PATH=${nettools}/sbin:$PATH - for i in $(cd /sys/class/net && ls -d *); do - if ! for j in ${toString ignoredInterfaces}; do echo $j; done | grep -F -x -q \"$i\"; then - echo \"Running dhclient on $i\" - interfaces=\"$interfaces $i\" - fi - done + # Determine the interface on which to start dhclient. + interfaces= - if test -z \"$interfaces\"; then - echo 'No interfaces on which to start dhclient!' - exit 1 - fi + for i in $(cd /sys/class/net && ls -d *); do + if ! for j in ${toString ignoredInterfaces}; do echo $j; done | grep -F -x -q "$i"; then + echo "Running dhclient on $i" + interfaces="$interfaces $i" + fi + done - mkdir -m 755 -p ${stateDir} + if test -z "$interfaces"; then + echo 'No interfaces on which to start dhclient!' + exit 1 + fi - exec ${dhcp}/sbin/dhclient -d $interfaces -e \"PATH=$PATH\" -lf ${stateDir}/dhclient.leases -end script - "; - }]; - }; + mkdir -m 755 -p ${stateDir} + + exec ${dhcp}/sbin/dhclient -d $interfaces -e "PATH=$PATH" -lf ${stateDir}/dhclient.leases + end script + ''; + }]; + + environment.etc = ifEnable + [ # Dhclient hooks for emitting ip-up/ip-down events. + { source = dhclientExitHooks; + target = "dhclient-exit-hooks"; + } + ]; + } |