1

I have a 16.04 Desktop box that connects to the internet via WiFi. For ease of remote management, wlan0 is configured via /etc/network/interfaces instead of network manager.

I have a systemd service that is enabled to start on boot. This service is set to start after default.target like so:

[Unit]
After=default.target

[Service]
Type=simple
ExecStart=/usr/bin/node main.js"
Restart=always

[Install]
WantedBy=default.target

This service starts immediately if I boot up the box in range of its wifi network, because dhclient immediately receives an IP. But if I boot up my system where it can't get on the wifi, my service sits around and waits for dhclient to give up before kicking off. This service waits precisely the 300 seconds specified in the /etc/dhclient/dhclient.conf timeout 300 stanza.

My understanding of After=default.target was that it would NOT wait on network. After=network.target is the tool to do that. If I configure my wifi with Network Manager instead of /etc/network/interfaces, the service gets started immediately regardless of network availability.

How can I get my service to start regardless of the status of dhclient while still using /etc/network/interfaces?

tyleha
  • 254

1 Answers1

1

The answer, it appears, is to use the mysterious allow-hotplug statement in /etc/network/interfaces as I learned from https://askubuntu.com/a/868445/358498:

allow-hotplug wlan0
iface wlan0 inet dhcp
...

systemd no longer waits on network to kick of a service that depends on default.target. Why allow-hotplug makes such a difference is a bit unclear to me, as there is no true "hotplug" event going on in my system. One resource says:

There's not much documentation on what allow-hotplug actually does. man interfaces (a fairly good man page, BTW) implies that ifup will refuse to bring up an interface unless allow-hotplug is set; but if the network is being started via /etc/init.d/networking start either way, why do different things happen depending on whether allow-hotplug is present? It's all very confusing, but take my word for it, you need allow-hotplug if you're using PCMCIA or Cardbus (or probably USB).

tyleha
  • 254