Comment 5 for bug 1918141

Revision history for this message
Niklas Edmundsson (niklas-edmundsson) wrote :

OK, getting the network delay got a little bit convoluted as you can't clear dependencies with overrides but instead have to copy the unit file and edit it.

I'm no systemd expert so this can probably be improved, but on a focal VM host of ours (KVM/Ganeti) that uses systemd-networkd I needed to do this, if you're using some other network setup scheme you'll need to adapt accordingly:

* cp /lib/systemd/system/systemd-networkd.service /etc/systemd/system/systemd-networkd.service
** Edit /etc/systemd/system/systemd-networkd.service:
*** Comment out Before= and Wants=
*** Add in [Unit] section, Before= without network.target and After=/Wants= fakenet.service:
**** Before=multi-user.target shutdown.target
**** After=fakenet.service
**** Wants=fakenet.service
*** Add in [Service] section:
**** ExecStartPre=/bin/sleep 10
* Create /etc/systemd/system/fakenet.service with content as [1] (bottom of comment)
* systemctl daemon-reload
* systemctl enable fakenet
* It turned out that systemd-resolved also messed with network.target, so I just disabled it
** Edit /etc/resolv.conf to contain usable DNS resolver
** systemctl stop systemd-resolved
** systemctl mask systemd-resolved
** Check /etc/resolv.conf again and verify that you can do DNS lookups

reboot, and then verify with systemd-analyze plot > boot.svg that timings are right, you should have network.target and then 10s or so later network-online.target (I just load boot.svg into a browser and use find to search in the file). If not you have to find the culprit that has a Before=network.target and edit or disable.

You should also find that nfs-server starts a few seconds before the network is available, and systemctl status nfs-server should show exportfs: Failed to resolve errors.

Hope this helps to QA/reproduce.

[1] fakenet.service:
[Unit]
Description=Fake network.target
DefaultDependencies=no
After=systemd-udevd.service network-pre.target systemd-sysusers.service systemd-sysctl.service
Before=network.target multi-user.target shutdown.target
Conflicts=shutdown.target
Wants=network.target

[Service]
Type=oneshot
ExecStart=/bin/true

[Install]
WantedBy=multi-user.target