Systemd broken network.online target workaround

man systemd.special says:

Units that strictly require a configured network connection should pull in network-online.target (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:

[Unit]
Wants=network-online.target
After=network-online.target

Here is an ugly workaround for that:

[Unit]
Wants=network-online.target
After=network-online.target

[Service]
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

No comments

You today

Comments are closed