1

I am trying to start a init.d daemon on Debian 8 after network and DNS is up and running. That's the script I am using:

### BEGIN INIT INFO
# Provides:          local_daemon
# Required-Start:    $all $local_fs $remote_fs $network $named $time $syslog
# Required-Stop:     $all $local_fs $remote_fs $network $named $time $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts a Daemon.
# Description:       Starts a custom daemon.
### END INIT INFO

I have several servers and this mostly works. However, in some cases DNS is not yet ready when the script is called. So, the daemon is not be able to connect to e.g. www.domain.com while it is run. Eventually DNS is ready, but it's after the script is run (not at the time when it is run).

Question: How can I force DNS to be ready when the script is called? My assumption was that $named in "Required-Start:" is responsible for DNS to be setup and ready. This doesn't seem to be the case. How can I force a script to be executed only when domain name resolution (DNS) & networking is ready?

EDIT 2017-01-26: thanks for the feedback. It's a LIVE-server and my Linux skills are rudimentary at best. I'd rather not break things while they are working fine otherwise. Anyhow, I settled with a 20 second sleep before the server is started, which seems to be working fine. Yes, I am very well aware that this is a "hack":

start() {
  # wait a while to make sure the network is ready!
  sleep 20

  # run the server
  ...
}

case "$1" in
start)
  # starts the server in a separate thread
  start &
  ;;
stop)
  # stop: we do nothing special
  ;;
*)
  ;;
esac
exit 0
noblemaster
  • 111
  • 2
  • 3
    Don't waste your time with old-style init scripts. Use a systemd unit and [wait for the network to be online](https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/). – Michael Hampton Jan 25 '17 at 08:10
  • In the meantime, I also have switched to systemd using `network-online.target` for `Wants` & `After` to no avail. There seems to be no alternative besides a "sleep 20". – noblemaster Mar 18 '18 at 06:44
  • Why is DNS not available when the server is connected to the network? Is it running its own DNS server, maybe? – Michael Hampton Mar 18 '18 at 11:42
  • I believe it's still initializing DNS while it tells systemd it's ready, while in actual fact it's not? DNS eventually works, it's just that it doesn't work when "network-online.target" claims to be ready. No, I am not running a DNS server. – noblemaster Mar 19 '18 at 05:10

0 Answers0