* Move the dhclient/wpa_supplicant restart actions out of the ifplugd

module.

svn path=/nixos/trunk/; revision=32409
This commit is contained in:
Eelco Dolstra 2012-02-19 22:53:25 +00:00
parent 5c6165ef9f
commit 1707d1130f
3 changed files with 36 additions and 14 deletions

View File

@ -116,12 +116,16 @@ in
powerManagement.resumeCommands = powerManagement.resumeCommands =
'' ''
export PATH=${config.system.build.upstart}/sbin:$PATH ${config.system.build.upstart}/sbin/restart dhclient
initctl restart wpa_supplicant '';
initctl restart dhclient
networking.interfaceMonitor.commands =
''
if [ "$status" = up ]; then
${config.system.build.upstart}/sbin/restart dhclient
fi
''; '';
}; };
} }

View File

@ -6,6 +6,8 @@ let
inherit (pkgs) ifplugd; inherit (pkgs) ifplugd;
cfg = config.networking.interfaceMonitor;
# The ifplugd action script, which is called whenever the link # The ifplugd action script, which is called whenever the link
# status changes (i.e., a cable is plugged in or unplugged). We do # status changes (i.e., a cable is plugged in or unplugged). We do
# nothing when a cable is unplugged. When a cable is plugged in, we # nothing when a cable is unplugged. When a cable is plugged in, we
@ -14,10 +16,9 @@ let
plugScript = pkgs.writeScript "ifplugd.action" plugScript = pkgs.writeScript "ifplugd.action"
'' ''
#! ${pkgs.stdenv.shell} #! ${pkgs.stdenv.shell}
if test "$2" = up; then iface="$1"
initctl stop dhclient status="$2"
initctl start dhclient ${cfg.commands}
fi
''; '';
in in
@ -30,21 +31,33 @@ in
networking.interfaceMonitor.enable = mkOption { networking.interfaceMonitor.enable = mkOption {
default = false; default = false;
description = " description = ''
If <literal>true</literal>, monitor Ethernet interfaces for If <literal>true</literal>, monitor Ethernet interfaces for
cables being plugged in or unplugged. When this occurs, the cables being plugged in or unplugged. When this occurs, the
<command>dhclient</command> service is restarted to <command>dhclient</command> service is restarted to
automatically obtain a new IP address. This is useful for automatically obtain a new IP address. This is useful for
roaming users (laptops). roaming users (laptops).
"; '';
}; };
networking.interfaceMonitor.beep = mkOption { networking.interfaceMonitor.beep = mkOption {
default = false; default = false;
description = " description = ''
If <literal>true</literal>, beep when an Ethernet cable is If <literal>true</literal>, beep when an Ethernet cable is
plugged in or unplugged. plugged in or unplugged.
"; '';
};
networking.interfaceMonitor.commands = mkOption {
default = false;
description = ''
Shell commands to be executed when the link status of an
interface changes. On invocation, the shell variable
<varname>iface</varname> contains the name of the interface,
while the variable <varname>status</varname> contains either
<literal>up</literal> or <literal>down</literal> to indicate
the new status.
'';
}; };
}; };
@ -52,7 +65,7 @@ in
###### implementation ###### implementation
config = mkIf config.networking.interfaceMonitor.enable { config = mkIf cfg.enable {
jobs.ifplugd = jobs.ifplugd =
{ description = "Network interface connectivity monitor"; { description = "Network interface connectivity monitor";
@ -68,7 +81,7 @@ in
''; '';
}; };
environment.systemPackages = [ifplugd]; environment.systemPackages = [ ifplugd ];
}; };

View File

@ -63,6 +63,11 @@ in
+ (optionalString (config.networking.WLANInterface != null) "-i ${config.networking.WLANInterface}"); + (optionalString (config.networking.WLANInterface != null) "-i ${config.networking.WLANInterface}");
}; };
powerManagement.resumeCommands =
''
${config.system.build.upstart}/sbin/restart wpa_supplicant
'';
}; };
} }