Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Apr 2010 08:54:38 -0500
From:      Brandon Gooch <jamesbrandongooch@gmail.com>
To:        Jeremy Chadwick <freebsd@jdc.parodius.com>
Cc:        freebsd-stable@freebsd.org, Phil <Phil@amdg.etowns.org>
Subject:   Re: rc(8) script -- waiting for the network to become usable
Message-ID:  <y2z179b97fb1004270654wb22a519u4e1d360a55c2dca7@mail.gmail.com>
In-Reply-To: <20100427030244.GA70237@icarus.home.lan>
References:  <20100418213727.GA98129@icarus.home.lan> <C599C5C348B448ADB9CD1BF0B9EB27A5@black> <20100427030244.GA70237@icarus.home.lan>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Apr 26, 2010 at 10:02 PM, Jeremy Chadwick
<freebsd@jdc.parodius.com> wrote:
> On Tue, Apr 27, 2010 at 09:48:41AM +1000, Phil wrote:
>> Jeremy,
>> A good proposal to improve start-up robustness. If I may suggest,
>> waitnetwork_ip should include a short list of alternate IP's in
>> the event of a local network outage, or DOS, etc. =A0Something like:
>> waitnetwork_ip=3D"IP1 IP2 IP3"
>>
>> Having multiple target IP's will improve the likelihood of timely
>> booting when silly/nasty things happen on the wider network.
>>
>> Good idea to have incorporated into the base system.
>
> Phil,
>
> I brought this point up in my post on -rc and -net, actually. =A0I've
> since extended the script to support multiple IPs in $waitnetwork_ip
> (wasn't that hard). =A0The logic is that if any of the IPs pass the ping
> test, then the network connection is considered usable.
>
> Attached is the modified script. =A0I'll be updating the version on my
> server (HTTP) momentarily.
>
> --
> | Jeremy Chadwick =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0=
 =A0 =A0 =A0 jdc@parodius.com |
> | Parodius Networking =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 http://=
www.parodius.com/ |
> | UNIX Systems Administrator =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0Mountain =
View, CA, USA |
> | Making life hard for others since 1977. =A0 =A0 =A0 =A0 =A0 =A0 =A0PGP:=
 4BD6C0CB |
>
>
> #!/bin/sh
> #
> # $FreeBSD: $
> #
>
> # PROVIDE: waitnetwork
> # REQUIRE: NETWORKING
> # BEFORE: mountcritremote
> # KEYWORD: nojail
>
> # XXX - Once/if committed to base, it's better to have mountcritremote
> # XXX - REQUIRE waitnetwork, rather than use the above BEFORE line.
>
> . /etc/rc.subr
>
> name=3D"waitnetwork"
> rc_var=3D`set_rcvar`
>
> start_cmd=3D"waitnetwork_start"
> stop_cmd=3D":"
>
> # XXX - Once/if committed to base, the following defaults should
> # XXX - be placed into src/etc/defaults/rc.conf instead of here
> # XXX - Also be sure to keep waitnetwork_ip=3D"" commented out!
>
> waitnetwork_enable=3D"NO" =A0 =A0 =A0 =A0 # Wait for network availability=
 before
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0# continui=
ng with NETWORKING rc scripts
> #waitnetwork_ip=3D"" =A0 =A0 =A0 =A0 =A0 =A0 =A0# IP address to ping
> waitnetwork_count=3D"5" =A0 =A0 =A0 =A0 =A0 # ping count (see ping(8) -c =
flag)
> waitnetwork_timeout=3D"60" =A0 =A0 =A0 =A0# ping timeout (see ping(8) -t =
flag)
>
> waitnetwork_start()
> {
> =A0 =A0 =A0 =A0local ip rc success
>
> =A0 =A0 =A0 =A0success=3D0
>
> =A0 =A0 =A0 =A0if [ -z "${waitnetwork_ip}" ]; then
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0warn "You must define one or more IP addre=
sses in waitnetwork_ip"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return
> =A0 =A0 =A0 =A0fi
>
> =A0 =A0 =A0 =A0for ip in ${waitnetwork_ip}; do
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0echo "Waiting for ${ip} to respond to ICMP=
..."
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if [ -z "${waitnetwork_timeout}" ]; then
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/sbin/ping -c ${waitnetwor=
k_count} ${ip} >/dev/null 2>&1
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0rc=3D$?
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0info "Using timeout of ${w=
aitnetwork_timeout} seconds"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/sbin/ping -t ${waitnetwor=
k_timeout} -c ${waitnetwork_count} ${ip} >/dev/null 2>&1
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0rc=3D$?
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0fi
>
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if [ $rc -eq 0 ]; then
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0echo "Host reachable; netw=
ork considered available."
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0else
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0echo "No response from hos=
t."
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0fi
> =A0 =A0 =A0 =A0done
>
> =A0 =A0 =A0 =A0echo "Exhausted IP list. =A0Continuing with startup, but b=
e aware you may"
> =A0 =A0 =A0 =A0echo "not have a fully functional networking layer at this=
 point."
> }
>
> load_rc_config $name
> run_rc_command "$1"

Not to hijack the thread, but this type of clean, quality work (even
though some consider it a hack), really helps a lot of people out.

I wonder, has anyone ever brought up the idea of an "rc repository" or
something similar, for rc scripts and/or configs that may help many,
but for whatever reason, will not be included in the base system?

I'm thinking of something more "official", hosted at the freebsd.org
domain. Maybe in the same vein as:

http://www.sun.com/bigadmin/home/index.jsp

Shields up,

-Brandon



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?y2z179b97fb1004270654wb22a519u4e1d360a55c2dca7>