23

I am trying to write a unit file for hostapd on Debian.

The hostapd daemon seems to need the interface for the associated Wifi interface to be up before it is run or else it SEGV's.

I've tried network-online.target, but still get the SEGV. I think this is because network-online.target only needs to see ANY interface up, and other interfaces comes up before the Wifi interface is ready enough for hostapd to work.

What is the best way to have a service wait for a specific interface to be up before starting?

1 Answer 1

25

Since systemd 219, you may use systemd's systemd-networkd-wait-online tool directly, with an --interface parameter to specify the interface to wait for. For example:

ExecStartPre=/usr/lib/systemd/systemd-networkd-wait-online --interface=$IFACE 

However, there is a caveat. This tool needs systemd-networkd to be running, even if it does nothing in your configuration. On the other hand, starting with the same systemd 219, systemd-networkd is socket-activatable and automatically exits on idle. So everything you need is to pull in its socket.

Putting it all together, modifications to unit file will look like this (with $IFACE substituted with your desired interface):

[Unit] Requires=systemd-networkd.socket After=systemd-networkd.socket ... [Service] ExecStartPre=/usr/lib/systemd/systemd-networkd-wait-online --interface=$IFACE ExecStart=/usr/bin/hostapd ... ... 
2
  • 2
    Yes,this is exactly what I want. Unfortunately I am stuck on Debian 4.6.3 with systemd 44, so can't use it. Any ideas on how to make it work on this platform? Thanks! Commented Jun 30, 2015 at 14:43
  • 4
    @bigjosh, you can always do something like perl -e 'sleep 1 until -e "/sys/class/net/myinterface"' in your ExecStartPre Commented May 15, 2019 at 13:23

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.