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