Systemd broken target workaround

man systemd.special says:

Units that strictly require a configured network connection should pull in (via a Wants= type dependency) and order themselves after it.

Despite that, I ran into a problem: service that requires outside network to be immediately available fails to start with configuration like described in manual:


Here is an ugly workaround for that:


ExecStart=sh -c "while ! ip -4 r | grep ^default; do echo waiting for ipv4 default route to appear; sleep 0.5; done"
ExecStart=<actual service here>

If you want not just default route available, but certain IP address:

ExecStart=sh -c "while ! ping -c 1 -W 0.5 <IP>; do true; done"

License: This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License Share: share on reddit share on hacker news share on facebook share on twitter share on linkedin share on slashdot