3

Is there a better way to ensure that an ethernet port is configured before continuing through startup init scripts? When 802.3ad bonded ethernet is configured on Ubuntu, it takes some time before it finishes protocol negotiation and starts passing packets, because the networking script just configures, but does not verify that traffic is being passed. As a result, this can throw off some of the other network dependent scripts, like the init for drbd. Right now, I just have a loop that pings the gateway in a startup script, but this seems less than optimal:

GATEWAYIP=10.0.0.1
while ( ! ping -c 1 $GATEWAYIP  ); do
   echo gateway not up
done
Pete Ashdown
  • 3,040

1 Answers1

1

This is a pretty specific use case you have with DRBD in line after networking. As I don't have much DRBD experience, I'm not sure how fast it will try to establish. Perhaps you could get by with simply detecting when the IP is bound to the interface instead of waiting until a ping responds (which adds that latency to the mix).

Perhaps something like;

#!/bin/bash
# Fetch Interface
BONDED_INTERFACE=$(cat /proc/net/dev | grep 'bon' | awk -F: '{print $1}')

# Determine Network Status
if [ "$BONDED_INTERFACE" ]; then
    BONDED_IP=$(/sbin/ifconfig ${BONDED_INTERFACE} | sed -n  -e '/Bcast/p' | cut -d : -f 2 | awk '{print $1}')
    while [ "${#BONDED_IP}" -le "0" ]; do
        echo "No IP Present on The Interface";
        BONDED_IP=$(/sbin/ifconfig ${BONDED_INTERFACE} | sed -n  -e '/Bcast/p' | cut -d : -f 2 | awk '{print $1}')
    done
    echo "The Interface IP is: $BONDED_IP";
else
    echo "No Bonded Interface Found";
fi

I suppose outside of debugging the above script would make more sense calling a sleep for a time duration rather then echoing it's output.

If this still isn't quite what you want, perhaps there is something to be done in NetworkManager or maybe trying to detect the link state (carrier sense). Hope I was some help.

krondor
  • 538
  • Now that I think about it, I'm wondering if perhaps a more elegant hack would be to throw a delay into the init script for the network. It seems like it should be a predictable time for the network to establish itself... – krondor Jun 27 '11 at 23:55
  • The 802.3ad bonded interface can be completely setup yet not passing traffic because the negotiation hasn't finished on the switch. The only way I can see to make sure this is happening is a ping test to the gateway. – Pete Ashdown Jun 28 '11 at 15:41
  • What about setting a delay in the network startup script? It seems the time for negotiation should be consistent should it not? Otherwise I don't see a better solution then the ping test you're doing already. – krondor Jun 28 '11 at 15:50