loki icon indicating copy to clipboard operation
loki copied to clipboard

After=network.target should be After=network-online.target

Open udf2457 opened this issue 1 year ago • 2 comments
trafficstars

In all your service files, After=network.target should be After=network-online.target.

Failure to do so will lead to flaky, unpredictable behaviour.

See man systemd.special, it says of network.target that:

This unit is supposed to indicate when network functionality is available, but it is only very weakly defined

And the rest of the man-page section about network.target basically appears to imply you should only rely on it during the shutdown process, not during boot.

Meanwhile the man systemd.special on network-online.target is pretty clear, e.g. :

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

udf2457 avatar Apr 22 '24 11:04 udf2457

Thanks for pointing this out @udf2457

https://systemd.io/NETWORK_ONLINE/ even suggests to use

After=network-online.target
Wants=network-online.target

chaudum avatar Apr 23 '24 07:04 chaudum

@chaudum Regarding the suggestion, indeed.

After= is simply ordering, Wants= provides the actual hard-dependency.

So best practice in situations such as network-online is indeed to have both, because you actually want the actual hard-dependency for obvious reasons. :wink:

udf2457 avatar Apr 23 '24 09:04 udf2457