From owner-freebsd-current@FreeBSD.ORG Wed Mar 18 07:52:11 2009 Return-Path: Delivered-To: current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7883F106566C; Wed, 18 Mar 2009 07:52:11 +0000 (UTC) (envelope-from dhorn2000@gmail.com) Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.31]) by mx1.freebsd.org (Postfix) with ESMTP id 1B0B78FC17; Wed, 18 Mar 2009 07:52:11 +0000 (UTC) (envelope-from dhorn2000@gmail.com) Received: by yw-out-2324.google.com with SMTP id 5so269725ywh.13 for ; Wed, 18 Mar 2009 00:52:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=lalOwfR1gSAt0g1Zgz7jp/1feDvRREkqAngJZBPl0yU=; b=WALsjM9aWymqL9GEMilFugRI8rYBisxKfQq2YFF4Ml+OkpQdIvyU/DFhIvvZTrgCcn gwXToswgE/ozF1CyGulqmME0a+Ijlk5Y7wTJel/32EeDgZ7/B53Tgqkz3cI+W3XJ9VKw YDi+1vnbL7vc8hfg6Agi1woSw+O26WG3EuMh0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=Kg3O+bGogP/9mJ6KvwgIIzE8AyAwvlbZgzAlPKzDWNRPp4WzEsCLAXkbH2t7NzynVz sJMDyA2HNjFNYIuHguHxXnD5MKr/Tly/dpiRBAzshQgjyY0chIqNWhUt/2hb7v+AYyEf DPUfUMyNZ4EtkoSyDEKAsASIPoccWN16l912Q= MIME-Version: 1.0 Received: by 10.231.20.2 with SMTP id d2mr370598ibb.27.1237362730351; Wed, 18 Mar 2009 00:52:10 -0700 (PDT) In-Reply-To: <49B4382D.9010403@FreeBSD.org> References: <2fd864e0903020512i22b2c31fg487aaf37fed6398b@mail.gmail.com> <584bfc3f0903030833k70405609q7e2d3b28c8cf4c29@mail.gmail.com> <20090303180307.GA11134@lor.one-eyed-alien.net> <584bfc3f0903032212x25831c5bi35d9b637c1896e1d@mail.gmail.com> <7d6fde3d0903040004y1fcbb086i355cd0113717620b@mail.gmail.com> <20090304164953.GB1209@lor.one-eyed-alien.net> <49B397A4.8090508@gmail.com> <20090308180934.GA9147@lor.one-eyed-alien.net> <200903082046.n28Kkvfn005494@hergotha.csail.mit.edu> <49B4382D.9010403@FreeBSD.org> Date: Wed, 18 Mar 2009 03:52:10 -0400 Message-ID: <25ff90d60903180052q4f94690fie35905d8b9a2f75b@mail.gmail.com> From: David Horn To: Doug Barton Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: current@freebsd.org Subject: Re: The rc.d mess strikes back X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Mar 2009 07:52:11 -0000 On Sun, Mar 8, 2009 at 5:27 PM, Doug Barton wrote: > Garrett Wollman wrote: >> I've generally solved this by hacking a little script into the order >> just after named to hold back the boot until named is able to resolve >> an external hostname. > > I've been following this thread (and thinking about your previous > posts on this topic Garrett) and I'm starting to think that having > this as an option in the base is the Right AnswerTM. Off hand I'd say > that we would need options for what hostname to ping, and whether to > use the local name server or just what's in resolv.conf, but that is > trivial stuff. Can I trouble you to post your script? In case anyone is interested, here is my version of the "wait until the network works" rc.d script: #!/bin/sh # # Copyright (c) 2009 The FreeBSD Project. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE PROJECT ``AS IS'' AND ANY EXPRESS OR # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE PROJECT BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # # PROVIDE: network_is_working # REQUIRE: NETWORKING # BEFORE: DAEMON # KEYWORD: nojail . /etc/rc.subr name="network_is_working" rcvar=`set_rcvar network_is_working` start_cmd="isworking_start" # rc.conf variables: #network_is_working_enable="YES" #network_is_working_timeout="90" #network_is_working_test="dns" #network_is_working_host="www.freebsd.org" # DNS test is the most basic, and can use ipv4 or ipv6 for transport, but is # rarely blocked by firewalls, so is the default for this script. ipv4/ipv6 # selection is based upon the user /etc/resolv.conf, so not in control of # this script. Also the slowest test, and does not respond well to ^C # Of course dns does not stress a central server, which is a plus. dns_test() { up="`host -W 1 -t A $host >/dev/null && echo -n "true"`" } # PING test is setup to be ipv4 only in this script, but also checks dns of # course. icmp can be blocked by firewalls. ping_test() { up="`ping -c1 -W 1 $host >/dev/null 2>&1 && echo -n "true"`" } # TCP test is the most robust, as it checks the default route, dns, and can # automatically function with either ipv4 or ipv6, but of course the user must # have a clear outbound connection to the net on port 80. While netcat (nc) # can support proxies, no effort has been made to auto-detect, or use/pass # proxy in this script. tcp_test() { up="`echo "^D" | nc -w 1 $host 80 >/dev/null 2>&1 && echo -n "true"`" } isworking_start() { up="false" num_nameservers="`grep -c "nameserver" /etc/resolv.conf`" if [ $num_nameservers -eq 0 ]; then echo "" warn "No nameservers defined in /etc/resolv.conf" exit 1 fi if [ -z "`ifconfig -lu | tr " " "\n" | grep -v 'lo0'`" ]; then echo "" warn "No interfaces properly configured and up." exit 1 fi if [ -z $network_is_working_timeout ]; then network_is_working_timeout="90" fi if [ -z $network_is_working_test ]; then network_is_working_test="dns" fi # Use a dns name that has ipv4 host (A) record and ipv6 host (AAAA) record # Use a host that allows both ipv4 and ipv6 ping # Use a host that listens on tcp port 80 on both ipv4 and ipv6 if [ -z "$network_is_working_host" ]; then network_is_working_host="www.freebsd.org" fi host="$network_is_working_host" case $network_is_working_test in [Pp][Ii][Nn][Gg]) func=ping_test ;; [Dd][Nn][Ss]) func=dns_test # host command takes longer, so adjust timeout # (~ 2 sec per query per nameserver) network_is_working_timeout=`expr "$network_is_working_timeout" / 2` network_is_working_timeout=`expr "$network_is_working_timeout" / "$num_nameservers"` ;; [Tt][Cc][Pp]) func=tcp_test ;; esac debug "Now testing using: $func" $func if [ "${up}" != "true" ]; then echo -n "Hit Ctrl+C to Abort waiting for network to come alive.." fi while [ "${up}" != "true" ]; do debug "waiting for $func to return true" $func sleep 1 && echo -n "." network_is_working_timeout=`expr $network_is_working_timeout - 1` if [ "$network_is_working_timeout" -le 0 ]; then echo "" warn "Timeout while waiting for network to respond." exit 1 break fi done exit 0 } load_rc_config $name run_rc_command "$1" Feel free to use/abuse/alter/trash/ignore as needed. --Thanks! --Dave