Ubuntu – How to bring up a network interface only if it is physically present in Ubuntu 14.04

12.0414.04bootnetworkingwireless

This is a follow-up on my old question:

What would be the best way to make kernel bring a network interface up
only if it is physically plugged in? So, if it doesn't exist, just
move on with initializing other interfaces (if any) and continue to
the login screen, without "waiting for network configuration" delay.

The solution then came up with then was the following in etc/network/interfaces, it used to work in 12.04:

auto wlan9
iface wlan9 inet manual
        wpa-ssid MYSSD
        wpa-psk MYKEY
        wpa-proto RSN
        wpa-pairwise CCMP
        wpa-group CCMP
        wireless-power off
        pre-up if [ -f /sys/class/net/wlan9/operstate ]; then ifconfig wlan9 up; fi
        up if [ -f /sys/class/net/wlan9/operstate ]; then dhclient wlan9; fi

Unfortunately, it stopped working once I upgraded to 14.04 Trusty Tahr. If the interface is physically absent (i.e. the USB WiFi card unplugged), I again experience the 2 minutes "waiting for network configuration" delay.

How can I get the same logic working in 14.04?

Best Answer

You can use an upstart job for this. Rip out the pre-up and up sections then make a file /etc/init/network-interface_wlan9.conf :

start on net-device-added INTERFACE=wlan9
task
exec ifup wlan9