summaryrefslogtreecommitdiffstats
path: root/package/initscripts/init.d/S40network
blob: a8d7c5df7863c0967e16af99b1cbd0ad97006fe4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
#!/bin/sh
#
# Start the network....
#

# Debian ifupdown needs the /run/network lock directory
mkdir -p /run/network

# In case we have a slow-to-appear interface (e.g. eth-over-USB),
# and we need to configure it, wait until it appears, but not too
# long either. WAIT_DELAY is in seconds.
WAIT_DELAY=15

wait_for_interfaces() {
	IFACES=$(awk '/^auto/ { print $2 }' /etc/network/interfaces)
	[ -n "$IFACES" ] || return

	printf "Waiting for network interfaces to appear"

	for i in $(seq $WAIT_DELAY); do
	    for IFACE in $IFACES; do
		if [ ! -e "/sys/class/net/$IFACE" ]; then
		    printf "."
		    sleep 1
		    continue 2
		fi
	    done

	    printf " ok\n"; return
	done

	printf " timeout\n"
	exit 1
}

case "$1" in
  start)
	wait_for_interfaces

 	echo "Starting network..."
	/sbin/ifup -a
	;;
  stop)
	printf "Stopping network..."
	/sbin/ifdown -a
	;;
  restart|reload)
	"$0" stop
	"$0" start
	;;
  *)
	echo "Usage: $0 {start|stop|restart}"
	exit 1
esac

exit $?

OpenPOWER on IntegriCloud