Re: rc(8) script -- waiting for the network to become usable

On Mon, Apr 26, 2010 at 10:02 PM, Jeremy Chadwick
<freebsd@xxxxxxxxxxxxxxxx> wrote:
On Tue, Apr 27, 2010 at 09:48:41AM +1000, Phil wrote:
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.  Something like:
waitnetwork_ip="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.


I brought this point up in my post on -rc and -net, actually.  I've
since extended the script to support multiple IPs in $waitnetwork_ip
(wasn't that hard).  The logic is that if any of the IPs pass the ping
test, then the network connection is considered usable.

Attached is the modified script.  I'll be updating the version on my
server (HTTP) momentarily.

| Jeremy Chadwick                                   jdc@xxxxxxxxxxxx |
| Parodius Networking              |
| UNIX Systems Administrator                  Mountain View, CA, USA |
| Making life hard for others since 1977.              PGP: 4BD6C0CB |

# $FreeBSD: $

# PROVIDE: waitnetwork
# 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



# 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="" commented out!

waitnetwork_enable="NO"         # Wait for network availability before
                               # continuing with NETWORKING rc scripts
#waitnetwork_ip=""              # IP address to ping
waitnetwork_count="5"           # ping count (see ping(8) -c flag)
waitnetwork_timeout="60"        # ping timeout (see ping(8) -t flag)

       local ip rc success


       if [ -z "${waitnetwork_ip}" ]; then
               warn "You must define one or more IP addresses in waitnetwork_ip"

       for ip in ${waitnetwork_ip}; do
               echo "Waiting for ${ip} to respond to ICMP..."

               if [ -z "${waitnetwork_timeout}" ]; then
                       /sbin/ping -c ${waitnetwork_count} ${ip} >/dev/null 2>&1
                       info "Using timeout of ${waitnetwork_timeout} seconds"
                       /sbin/ping -t ${waitnetwork_timeout} -c ${waitnetwork_count} ${ip} >/dev/null 2>&1

               if [ $rc -eq 0 ]; then
                       echo "Host reachable; network considered available."
                       echo "No response from host."

       echo "Exhausted IP list.  Continuing with startup, but be aware you may"
       echo "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
domain. Maybe in the same vein as:

Shields up,

freebsd-stable@xxxxxxxxxxx mailing list
To unsubscribe, send any mail to "freebsd-stable-unsubscribe@xxxxxxxxxxx"

Relevant Pages

  • Re: network deamons starting before network!
    ... Since updating to 8.X I noticed that network services were started ... added to the base system) to deal with this issue. ... If lagg devices offer that line in ifconfig, then the script will work ... Meaning, lagg0 might show link, but maybe that means ...
  • Re: rc(8) script -- waiting for the network to become usable
    ... I recently proposed addition of a new script to the rc framework which ... verifies that layer 3 network connectivity is up/functional ... about adding this to the base system. ...
  • Re: ntp woes (and more-general questions about startup and logging)
    ... the script didn't run the "stop" ... Our 10.4 machines are 10.4.7. ... been thinking that the underlying network, ... deny) what traffic (IP + port) goes to what port. ...
  • Re: split/isolate network
    ... R> as part of the network set-up? ... R> A script is how you would make it permanent. ... R> writing your own firewall rules. ... R> You'll also want to read up on NAT ...
  • Re: Modelling Complex Sentences
    ... re-inventing the network data model). ... If such as classifying node does not exist, ... Since people complained that dbd's scripts were too long, ... you typically use the CREATE/INSERT commands to ...