问题原文
原帖链接 · Brando__ · CC BY-SA 3.0
I've got a couple services, most notably nginx and ntpd, that depend on having working DNS resolution to start properly. Right now neither of these services start correctly at boot time, but do start fine when manually intervened on once the machine is up, with some messages in the logs about not being able to resolve names.
This leads me to believe I'm having a race condition with systemd. My servers point to 127.0.0.1 for their nameservers. Binded to localhost:53 is pdns-recursor. I've set ntp and nginx to be WantedBy pdns-recursor in their unit files as follows
[Unit]
WantedBy=pdns-recursor.service
However I still receive log messages in both nginx and ntp about failing to resolve names at boot time.
How can I verify that DNS is completely up before these services attempt to start? I am using Ubuntu 16.04
Aug 09 22:35:25 host.blah ntpd[3574]: restrict: ignoring line 21, address/host 'ntp.blah' unusable.
Aug 09 22:35:26 host.blah ntpd[3574]: restrict: ignoring line 23, address/host 'ntp.blah' unusable.
Aug 09 22:35:28 host.blah ntpd[3574]: restrict: ignoring line 25, address/host 'ntp.blah' unusable.
Aug 09 22:35:29 host.blah ntpd[3574]: restrict: ignoring line 27, address/host 'ntp.blah' unusable.
社区高分解答
原帖链接 · mianos · CC BY-SA 4.0
systemd is flexible enough to do this:
[Unit]
Description=Wait for DNS to come up using 'host'
After=nss-lookup.target
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'until host yourhost.com; do sleep 1; done'
[Install]
WantedBy=multi-user.target
Then you can depend on this unit in your unit file that requires dns to mount:
[Unit]
Description=mount nfs
After=dns-ready.service
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
