How to write systemd service to ensure start after dns service?

After upgrading to Kubuntu 19.04, I don't know how to write a service so that it can start after DNS service has been initialized.

In this past, I just use After=network.target, but now it doesn't work. I also tried After=network-online.target, but no luck.

So I think the problem is systemd-resolved, how could I solve this problem?


update:

ERROR: getaddrinfo: Temporary failure in name resolution
ERROR: failed to resolve the provided hostname

These are two related logs. So I can confirm the problem is related to DNS service.

7

1 Answer

Please add a dependency in your service file:

After=nss-lookup.target

This should ensure that host/name lookup is operable.

Further details are in the documentation:

nss-lookup.target

A target that should be used as synchronization point for all host/network name service lookups. Note that this is independent of UNIX user/group name lookups for which nss-user-lookup.target should be used. All services for which the availability of full host/network name resolution is essential should be ordered after this target, but not pull it in. systemd automatically adds dependencies of type After= for this target unit to all SysV init script service units with an LSB header referring to the "$named" facility.

To fully wait for network, the documentation of systemd directs you to add to your service:

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

and to confirm that the relevant "wait" service is enabled:

$ systemctl is-enabled NetworkManager-wait-online.service systemd-networkd-wait-online.service
disabled
enabled
8

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like