From owner-freebsd-rc@FreeBSD.ORG Thu Apr 15 09:10:42 2010 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 0C3A7106566B for ; Thu, 15 Apr 2010 09:10:42 +0000 (UTC) (envelope-from xfb52@dial.pipex.com) Received: from mk-outboundfilter-6.mail.uk.tiscali.com (mk-outboundfilter-6.mail.uk.tiscali.com [212.74.114.14]) by mx1.freebsd.org (Postfix) with ESMTP id 960BC8FC12 for ; Thu, 15 Apr 2010 09:10:41 +0000 (UTC) X-Trace: 199310628/mk-outboundfilter-6.mail.uk.tiscali.com/PIPEX/$PIPEX-INTERNET-ACCEPTED/None/80.192.24.142/None/xfb52@dial.pipex.com X-SBRS: None X-RemoteIP: 80.192.24.142 X-IP-MAIL-FROM: xfb52@dial.pipex.com X-SMTP-AUTH: xfb52@dial.pipex.com X-Originating-Country: GB/UNITED KINGDOM X-MUA: Mozilla/5.0 (X11; U; FreeBSD i386; en-GB; rv:1.8.1.18) Gecko/20081122 SeaMonkey/1.1.13 Mnenhy/0.7.6.0 X-IP-BHB: Once X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApEBADZyxktQwBiO/2dsb2JhbAAH2m2FDgQ X-IronPort-AV: E=Sophos;i="4.52,211,1270422000"; d="scan'208";a="199310628" X-IP-Direction: OUT Received: from cpc1-sgyl5-0-0-cust141.sgyl.cable.virginmedia.com (HELO [192.168.23.2]) ([80.192.24.142]) by smtp.pipex.tiscali.co.uk with ESMTP; 15 Apr 2010 10:00:33 +0100 Message-ID: <4BC6D5B1.3000107@dial.pipex.com> Date: Thu, 15 Apr 2010 10:00:33 +0100 From: Alex Zbyslaw User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-GB; rv:1.8.1.18) Gecko/20081122 SeaMonkey/1.1.13 Mnenhy/0.7.6.0 MIME-Version: 1.0 To: smyru@heron.pl References: <201004092358.o39NwXVE012127@freefall.freebsd.org> <20100413202145.M96857@heron.pl> In-Reply-To: <20100413202145.M96857@heron.pl> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-rc@FreeBSD.org Subject: Re: conf/145530: [rc.d] ntpdate(8): ntpdate rc needs wpa_supplicant to go online X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 15 Apr 2010 09:10:42 -0000 I don't think the attached script is quite what you want, but I use it to solve a similar problem. On my domestic network I have a gateway FreeBSD box that the entire local network sits behind, and I have the machine I use as my desktop. Both machines get switched off at least every night. Come switch on time, I don't always remember to boot the gateway first, and often got exactly this problem --- ntpdate failing because I had no external network connection. I was able to solve that by creating my own /usr/local/etc/rc.d script which runs before ntpdate and waits some amount of time for my gateway machine to come up. If I know I'm booting with no network I can just interrupt it with ^C. I'm sure that something similar would work for you. Whether such a solution is appropriate more generally I don't know but something like it should work for you, I think, without any mods being required to the base system. hth, --Alex $ egrep gateway_up /etc/rc.conf gateway_up_enable="YES" # Wait for gateway to come up gateway_up_host="192.168.23.3" In addition you can set e.g. gateway_up_external="some.domain.name" # External host we can ping gateway_up_wait=600 # wait 600s for gateway to come up gateway_up_external_wait=600 # wait 600s for external host to be available (e.g. waiting for named to start on gateway) #!/bin/sh # # $Id: gateway_up,v 1.4 2009/05/25 11:23:52 alex Exp $ # # PROVIDE: gateway_up # REQUIRE: NETWORKING syslogd named # BEFORE: ntpdate # KEYWORD: nojail . /etc/rc.subr name="gateway_up" rcvar=`set_rcvar` start_cmd="gateway_up_start" stop_cmd=":" : ${gateway_up_wait:=180} : ${gateway_up_external_wait:=180} [ ${gateway_up_wait} -lt 0 ] && gateway_up_wait=$((-${gateway_up_wait})) [ ${gateway_up_external_wait} -lt 0 ] && gateway_up_external_wait=$((-${gateway_up_external_wait})) gateway_up_start() { local external_host count echo_done if [ -z "$gateway_up_host" ]; then warn "gateway_up_host not set" return 1 fi if [ -z "$gateway_up_external" ]; then if [ -n "$ntpdate_hosts" ]; then "$gateway_up_external"="$ntpdate_hosts" elif [ -z "$ntpdate_hosts" -a -f ${ntpdate_config} ]; then gateway_up_external=`awk ' /^server[ \t]*127.127/ {next} /^(server|peer)/ {print $2} ' < ${ntpdate_config}` else warn "gateway_up_external unset and no ntp hosts found" fi fi if ! ping -W 1 -c 1 $gateway_up_host > /dev/null 2>&1; then # Wait for gateway host a maximum of ${gateway_up_wait} seconds echo -n "Waiting (roughly) ${gateway_up_wait}s for gateway ${gateway_up_host}: " if ! ping -o -t ${gateway_up_wait} $gateway_up_host > /dev/null 2>&1; then echo "not up...continuing" return 0 fi echo "done" fi # Wait for an external host to ping for a rough maximum of # ${gateway_up_external_wait} seconds, trying each in turn # for 2 seconds if [ -z "${gateway_up_external}" ]; then echo "No gateway_up_external hosts to check" return 0 fi count=0 echo_done=0 while [ $count -lt ${gateway_up_external_wait} ]; do for external_host in ${gateway_up_external}; do count=$((count+1)) #echo checking $external_host # SIGALRM somewhere (prints "Alarm clock") sometimes # if we try -o -t 1 if ping -W 100 -c 1 $external_host > /dev/null 2>&1; then if [ $echo_done -gt 0 ]; then echo "done" fi return 0 fi if [ $count -eq 1 ]; then echo -n "Waiting (roughly) ${gateway_up_external_wait}s for external connectivity: " echo_done=1 fi #echo "sleeping" sleep 2 done done if [ $echo_done -gt 0 ]; then echo "No connectivity...continuing" fi } load_rc_config $name run_rc_command "$1"