rc.d NETWORKING dependancy not waiting for network to be up

RW fbsd06 at mlists.homeunix.com
Mon Jun 11 19:32:15 UTC 2007


On Mon, 11 Jun 2007 09:28:26 -0400
Matt Pounsett <matt at conundrum.com> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> 
> It looks like the NETWORKING dummy dependancy doesn't actually cause  
> the its dependants to wait for networking to be up, but simply for  
> interfaces to be configured.  I'm wondering if this is actually  
> intended, or if it's an unavoidable design flaw, or what?
> 
> I'm noting on my systems that ntpdate and ntpd are trying to start  
> before the network is actually reachable, and therefore both have  
> issues starting.  ntpdate is unable to sync the clock properly
> before ntpd starts, and ntpd doesn't seem to ever be able to sync to
> a time server if it starts trying to contact one before the network
> is fully up... and needs to be restarted after boot in order for it
> to work properly.
> 
> I'm working around the issue by sticking a 20 second delay into /etc/ 
> rc.d/NETWORKING (this is probably way more than necessary, but I'm  
> allowing for a large margin of error) which seems to fix my problem,  
> but is obviously not ideal.

I wrote a lttle rcng  script to handle it it. It runs immediately
before ntpdate,and waits until it can ping my ISP's nameservers
(ignoring the 127.0.0.1 entry in resolv.conf), or you can specify ip
addresses.


$ cat /usr/local/etc/rc.d/networkwait
#!/bin/sh
#
# PROVIDE: networkwait
# REQUIRE: named
# BEFORE:  ntpdate

. /etc/rc.subr

networkwait_enable=${networkwait_enable:-"NO"}
name="networkwait"
rcvar=`set_rcvar`
stop_cmd=":"
start_cmd="wait_network"

wait_network(){
   if [ "$networkwait_ping_hosts" ] ; then
      host_list="${networkwait_ping_hosts}"
   else
      # No hosts supplied - use external nameservers
      host_list=`awk '/^ *nameserver/ {print $2}
        '< /etc/resolv.conf | grep -E -v '^127\.0+\.0+\.0*1'`
   fi
   echo -n "Waiting for network access ... "
   while true ; do
      for inet_host in $host_list ; do
         if ping -nc1  $inet_host 2>&1 > /dev/null ; then
            echo "ping to ${inet_host} succeeded."
            # Re-Sync ipfilter and pf in case
            # they had failed DNS lookups
            /etc/rc.d/ipfilter resync
            /etc/rc.d/pf resync
            exit 0
         fi
      done
      sleep 5
   done
}

load_rc_config ${name}
run_rc_command "$1"


More information about the freebsd-questions mailing list