Subversion Repositories configs

Rev

Rev 4 | Rev 97 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 - 1
#! /bin/bash
2
#
3
# network       Bring up/down networking
4
#
5
# chkconfig: 2345 10 90
6
# description: Activates/Deactivates all network interfaces configured to \
7
#              start at boot time.
8
#
9
### BEGIN INIT INFO
10
# Provides: $network
11
# Should-Start: iptables ip6tables
12
# Short-Description: Bring up/down networking
13
# Description: Bring up/down networking
14
### END INIT INFO
15
 
16
# Source function library.
17
. /etc/init.d/functions
18
 
19
if [ ! -f /etc/sysconfig/network ]; then
20
    exit 6
21
fi
22
 
23
. /etc/sysconfig/network
24
 
25
if [ -f /etc/sysconfig/pcmcia ]; then
26
	. /etc/sysconfig/pcmcia
27
fi
28
 
29
 
30
# Check that networking is up.
31
[ "${NETWORKING}" = "no" ] && exit 6
32
 
33
# if the ip configuration utility isn't around we can't function.
34
[ -x /sbin/ip ] || exit 1
35
 
36
CWD=$(pwd)
37
cd /etc/sysconfig/network-scripts
38
 
39
. ./network-functions
40
 
41
# find all the interfaces besides loopback.
42
# ignore aliases, alternative configurations, and editor backup files
43
interfaces=$(ls ifcfg* | \
44
	    LANG=C sed -e "$__sed_discard_ignored_files" \
45
		       -e '/\(ifcfg-lo$\|:\|ifcfg-.*-range\)/d' \
46
		       -e '/ifcfg-[A-Za-z0-9#\._-]\+$/ { s/^ifcfg-//g;s/[0-9]/ &/}' | \
47
	    LANG=C sort -k 1,1 -k 2n | \
48
	    LANG=C sed 's/ //')
49
rc=0
50
 
51
# See how we were called.
52
case "$1" in
53
  start)
54
	[ "$EUID" != "0" ] && exit 4
55
	rc=0
56
	# IPv6 hook (pre IPv4 start)
57
	if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
58
		/etc/sysconfig/network-scripts/init.ipv6-global start pre
59
	fi
60
 
61
	apply_sysctl
62
 
63
	# bring up loopback interface
64
	action $"Bringing up loopback interface: " ./ifup ifcfg-lo
65
 
66
	case "$VLAN" in
67
	  yes)
68
	    if [ ! -d /proc/net/vlan ] && ! modprobe 8021q >/dev/null 2>&1 ; then
69
		net_log $"No 802.1Q VLAN support available in kernel."
70
	    fi
71
	    ;;
72
	esac
73
 
74
	vlaninterfaces=""
75
	xdslinterfaces=""
76
	bridgeinterfaces=""
77
 
78
	# bring up all other interfaces configured to come up at boot time
79
	for i in $interfaces; do
80
		unset DEVICE TYPE SLAVE
81
		eval $(LANG=C fgrep "DEVICE=" ifcfg-$i)
82
		eval $(LANG=C fgrep "TYPE=" ifcfg-$i)
83
		eval $(LANG=C fgrep "SLAVE=" ifcfg-$i)
84
 
85
		if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
86
 
87
		if [ "$SLAVE" = "yes" ]; then
88
			continue
89
		fi
90
 
91
		if [ "$TYPE" = "xDSL" ]; then
92
		        xdslinterfaces="$xdslinterfaces $i"
93
			continue
94
		fi
95
 
96
		if [ "$TYPE" = "Bridge" ]; then
97
		        bridgeinterfaces="$bridgeinterfaces $i"
98
			continue
99
		fi
100
 
101
		if [ "${DEVICE%%.*}" != "$DEVICE"  -o  "${DEVICE##vlan}" != "$DEVICE" ] ; then
102
			vlaninterfaces="$vlaninterfaces $i"
103
			continue
104
		fi
105
 
106
		if LANG=C egrep -L "^ONBOOT=['\"]?[Nn][Oo]['\"]?" ifcfg-$i > /dev/null ; then
107
		        # this loads the module, to preserve ordering
108
			is_available $i
109
			continue
110
		fi
111
		# If we're in confirmation mode, get user confirmation.
112
		if [ -f /var/run/confirm ]; then
113
			confirm $i
114
			test $? = 1 && continue
115
		fi
116
		action $"Bringing up interface $i: " ./ifup $i boot
117
		[ $? -ne 0 ] && rc=1
118
	done
119
 
120
	# Bring up xDSL and VPN interfaces
121
	for i in $vlaninterfaces $bridgeinterfaces $xdslinterfaces ; do
122
            if ! LANG=C egrep -L "^ONBOOT=['\"]?[Nn][Oo]['\"]?" ifcfg-$i >/dev/null 2>&1 ; then
123
		# If we're in confirmation mode, get user confirmation.
124
		if [ -f /var/run/confirm ]; then
125
			confirm $i
126
			test $? = 1 && continue
127
		fi
128
		action $"Bringing up interface $i: " ./ifup $i boot
129
		[ $? -ne 0 ] && rc=1
130
	    fi
131
        done
132
 
133
	# Add non interface-specific static-routes.
134
	if [ -f /etc/sysconfig/static-routes ]; then
135
	   grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
136
              /sbin/route add -$args
137
	   done
138
	fi
139
	# Add non interface-specific static arp entries.
140
	if [ -f /etc/ethers ]; then
141
		/sbin/arp -f /etc/ethers
142
	fi
143
 
144
 	# IPv6 hook (post IPv4 start)
145
 	if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
146
 		/etc/sysconfig/network-scripts/init.ipv6-global start post
147
 	fi
148
	# Run this again to catch any interface-specific actions
149
	apply_sysctl
150
 
151
        touch /var/lock/subsys/network
152
 
153
	[ -n "${NETWORKDELAY}" ] && /bin/sleep ${NETWORKDELAY}
154
        ;;
155
  stop)
156
	[ "$EUID" != "0" ] && exit 4
157
  	# Don't shut the network down if root is on NFS or a network
158
	# block device.
159
        rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/" && $3 != "rootfs") { print $3; }}' /proc/mounts)
160
        rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
161
 
162
	if [[ "$rootfs" == nfs* || "$rootopts" =~ _r?netdev ]] ; then
34 - 163
	        net_log $"rootfs is on network filesystem, leaving network up"
4 - 164
		exit 1
165
	fi
166
 
167
  	# If this is a final shutdown/halt, check for network FS,
168
	# and unmount them even if the user didn't turn on netfs
169
	if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
170
		NETMOUNTS=$(findmnt -m -t nfs,nfs4,smbfs,ncpfs,cifs 2>/dev/null)
171
		if [ -n "$NETMOUNTS" ] ; then
172
			/etc/init.d/netfs stop
173
		fi
174
	fi
175
 
176
	vlaninterfaces=""
177
	xdslinterfaces=""
178
	bridgeinterfaces=""
179
	remaining=""
180
	rc=0
181
 
182
	# get list of bonding, vpn, and xdsl interfaces
183
	for i in $interfaces; do
184
		unset DEVICE TYPE
185
		eval $(LANG=C fgrep "DEVICE=" ifcfg-$i)
186
		eval $(LANG=C fgrep "TYPE=" ifcfg-$i)
187
 
188
		if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
189
 
190
		if [ "$TYPE" = "Bridge" ]; then
191
		        bridgeinterfaces="$bridgeinterfaces $i"
192
		        continue
193
		fi
194
		if [ "$TYPE" = "xDSL" ]; then
195
		        xdslinterfaces="$xdslinterfaces $i"
196
			continue
197
		fi
198
 
199
		if [ "${DEVICE%%.*}" != "$DEVICE"  -o  "${DEVICE##vlan}" != "$DEVICE" ] ; then
200
			vlaninterfaces="$vlaninterfaces $i"
201
			continue
202
		fi
203
		remaining="$remaining $i"
204
	done
205
 
206
	for i in $xdslinterfaces $bridgeinterfaces $vlaninterfaces $remaining; do
207
		(. ./ifcfg-$i
208
		if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
209
 
210
		if ! check_device_down $DEVICE; then
211
		   action $"Shutting down interface $i: " ./ifdown $i boot
212
		   [ $? -ne 0 ] && rc=1
213
		fi
214
		)
215
	done
216
 
217
	action $"Shutting down loopback interface: " ./ifdown ifcfg-lo
218
 
219
	sysctl -w net.ipv4.ip_forward=0 > /dev/null 2>&1
220
 
221
	# IPv6 hook (post IPv4 stop)
222
	if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
223
		/etc/sysconfig/network-scripts/init.ipv6-global stop post
224
	fi
225
 
226
        rm -f /var/lock/subsys/network
227
        ;;
228
  status)
229
	echo $"Configured devices:"
230
	echo lo $interfaces
231
 
232
	echo $"Currently active devices:"
233
	echo $(/sbin/ip -o link show up | awk -F ": " '{ print $2 }')
234
	;;
235
  restart|reload|force-reload)
236
        cd "$CWD"
237
	$0 stop
238
	$0 start
239
	rc=$?
240
	;;
241
  *)
242
        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
243
        exit 2
244
esac
245
 
246
exit $rc