network.online target reached too early

  • -

network.online target reached too early

Category : Linux , Systems , Ubuntu

In a.o. Ubuntu 15.10 the network.online target should be used to start services after the network is available. However the target returns too early, i.e. sometimes before an IP address is assigned.


As a quick work around a simple testscript will do. Use a suitable IP address, i.e the expected IP address of the own interface.

cat /root/are_we_online.sh
#!/bin/sh

h=192.168.1.246

while true; do
        ping -n -c 1 -w 3 $h >/dev/null 2>&1 && exit 0
        sleep 2
done

To use it for a specific service, i.e. /lib/systemd/system/.service, add

[Unit]
Wants=... network-online.target
After=... network-online.target
[Service]
ExecStartPre=/root/are_we_online.sh

If you need this for more than one service, you might want to create a separate service/target using the script, or modify the network-online.target.