S40network 1.55 KB
Newer Older
Ryan Jackson's avatar
Ryan Jackson committed
1 2 3 4 5 6 7
#!/bin/sh
#
# Start the network....
#

udhcpc_opts="-q"

8 9 10 11 12 13
if [ -f /etc/emulab/paths.sh ]; then
	. /etc/emulab/paths.sh
else
	BOOTDIR=/etc/testbed
fi

Ryan Jackson's avatar
Ryan Jackson committed
14
LOCKDIR=/var/lock/udhcpc.lock
15
SUCCESS_FLAG=$BOOTDIR/myip
Ryan Jackson's avatar
Ryan Jackson committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95

start() {
	interfaces=""
	child_pids=""
 	echo "Starting network..."
	for iface in `echo /sys/class/net/*`; do
		iface=${iface##*/}
		interfaces="$interfaces $iface"
		[ $iface = 'lo' ] && continue
		udhcpc $udhcpc_opts -i $iface> /var/log/udhcpc.log.$iface 2>&1 &
		child_pids="$child_pids $!"
	done
	timeout=30
	time=0
	while ! [ -f $SUCCESS_FLAG ] && [ $time -lt $timeout ]; do
		sleep 1
		time=`expr $time + 1`
	done

	if ! mkdir $LOCKDIR 2> /dev/null; then
		echo "*** ERROR: Timeout while searching for control network" 1>&2
		echo "*** ERROR: Killing all dhcp clients..." 1>&2
		kill -9 $child_pids
		killall default.script
		for iface in $interfaces; do
			ifconfig $iface down
		done
		route del default
		cat /dev/null > /etc/resolv.conf
		rmdir $LOCKDIR

		exit 1
	fi

	rc=0
	if ! [ -f $SUCCESS_FLAG ]; then
		echo "*** ERROR: Unable to find control network" 1>&2
		rc=2
	fi

	kill -9 $child_pids 2> /dev/null

	rmdir $LOCKDIR

	return $rc
}

stop() {
	echo -n "Stopping network..."
	for iface in `echo /sys/class/net/*`; do
		iface=${iface##*/}
		[ $iface = 'lo' ] && continue
		ifconfig $iface 0.0.0.0 down
	done
	rmdir $LOCKDIR
	rm -f $SUCCESS_FLAG
	cat /dev/null > /etc/resolv.conf
}
restart() {
	stop
	start
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart|reload)
  	restart
	;;
  *)
	echo $"Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?