Subversion Repositories configs

Rev

Rev 34 | 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
 
97 - 101
		if [ "$TYPE" = "IPSEC" ] || [ "$TYPE" = "IPIP" ] || [ "$TYPE" = "GRE" ]; then
102
			vpninterfaces="$vpninterfaces $i"
103
			continue
104
		fi
105
 
4 - 106
		if [ "${DEVICE%%.*}" != "$DEVICE"  -o  "${DEVICE##vlan}" != "$DEVICE" ] ; then
107
			vlaninterfaces="$vlaninterfaces $i"
108
			continue
109
		fi
110
 
111
		if LANG=C egrep -L "^ONBOOT=['\"]?[Nn][Oo]['\"]?" ifcfg-$i > /dev/null ; then
112
		        # this loads the module, to preserve ordering
113
			is_available $i
114
			continue
115
		fi
116
		# If we're in confirmation mode, get user confirmation.
117
		if [ -f /var/run/confirm ]; then
118
			confirm $i
119
			test $? = 1 && continue
120
		fi
121
		action $"Bringing up interface $i: " ./ifup $i boot
122
		[ $? -ne 0 ] && rc=1
123
	done
124
 
125
	# Bring up xDSL and VPN interfaces
126
	for i in $vlaninterfaces $bridgeinterfaces $xdslinterfaces ; do
127
            if ! LANG=C egrep -L "^ONBOOT=['\"]?[Nn][Oo]['\"]?" ifcfg-$i >/dev/null 2>&1 ; then
128
		# If we're in confirmation mode, get user confirmation.
129
		if [ -f /var/run/confirm ]; then
130
			confirm $i
131
			test $? = 1 && continue
132
		fi
133
		action $"Bringing up interface $i: " ./ifup $i boot
134
		[ $? -ne 0 ] && rc=1
135
	    fi
136
        done
137
 
138
	# Add non interface-specific static-routes.
139
	if [ -f /etc/sysconfig/static-routes ]; then
140
	   grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
141
              /sbin/route add -$args
142
	   done
143
	fi
144
	# Add non interface-specific static arp entries.
145
	if [ -f /etc/ethers ]; then
146
		/sbin/arp -f /etc/ethers
147
	fi
148
 
149
 	# IPv6 hook (post IPv4 start)
150
 	if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
151
 		/etc/sysconfig/network-scripts/init.ipv6-global start post
152
 	fi
153
	# Run this again to catch any interface-specific actions
154
	apply_sysctl
155
 
156
        touch /var/lock/subsys/network
157
 
158
	[ -n "${NETWORKDELAY}" ] && /bin/sleep ${NETWORKDELAY}
159
        ;;
160
  stop)
161
	[ "$EUID" != "0" ] && exit 4
162
  	# Don't shut the network down if root is on NFS or a network
163
	# block device.
164
        rootfs=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/" && $3 != "rootfs") { print $3; }}' /proc/mounts)
165
        rootopts=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $4; }}' /etc/mtab)
166
 
167
	if [[ "$rootfs" == nfs* || "$rootopts" =~ _r?netdev ]] ; then
34 - 168
	        net_log $"rootfs is on network filesystem, leaving network up"
4 - 169
		exit 1
170
	fi
171
 
172
  	# If this is a final shutdown/halt, check for network FS,
173
	# and unmount them even if the user didn't turn on netfs
174
	if [ "$RUNLEVEL" = "6" -o "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" ]; then
175
		NETMOUNTS=$(findmnt -m -t nfs,nfs4,smbfs,ncpfs,cifs 2>/dev/null)
176
		if [ -n "$NETMOUNTS" ] ; then
177
			/etc/init.d/netfs stop
178
		fi
179
	fi
180
 
181
	vlaninterfaces=""
182
	xdslinterfaces=""
183
	bridgeinterfaces=""
184
	remaining=""
185
	rc=0
186
 
187
	# get list of bonding, vpn, and xdsl interfaces
188
	for i in $interfaces; do
189
		unset DEVICE TYPE
190
		eval $(LANG=C fgrep "DEVICE=" ifcfg-$i)
191
		eval $(LANG=C fgrep "TYPE=" ifcfg-$i)
192
 
193
		if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
194
 
97 - 195
		if [ "$TYPE" = "IPSEC" ] || [ "$TYPE" = "IPIP" ] || [ "$TYPE" = "GRE" ]; then
196
			vpninterfaces="$vpninterfaces $i"
197
			continue
198
		fi
199
 
4 - 200
		if [ "$TYPE" = "Bridge" ]; then
201
		        bridgeinterfaces="$bridgeinterfaces $i"
202
		        continue
203
		fi
204
		if [ "$TYPE" = "xDSL" ]; then
205
		        xdslinterfaces="$xdslinterfaces $i"
206
			continue
207
		fi
208
 
209
		if [ "${DEVICE%%.*}" != "$DEVICE"  -o  "${DEVICE##vlan}" != "$DEVICE" ] ; then
210
			vlaninterfaces="$vlaninterfaces $i"
211
			continue
212
		fi
213
		remaining="$remaining $i"
214
	done
215
 
216
	for i in $xdslinterfaces $bridgeinterfaces $vlaninterfaces $remaining; do
217
		(. ./ifcfg-$i
218
		if [ -z "$DEVICE" ] ; then DEVICE="$i"; fi
219
 
220
		if ! check_device_down $DEVICE; then
221
		   action $"Shutting down interface $i: " ./ifdown $i boot
222
		   [ $? -ne 0 ] && rc=1
223
		fi
224
		)
225
	done
226
 
227
	action $"Shutting down loopback interface: " ./ifdown ifcfg-lo
228
 
229
	sysctl -w net.ipv4.ip_forward=0 > /dev/null 2>&1
230
 
231
	# IPv6 hook (post IPv4 stop)
232
	if [ -x /etc/sysconfig/network-scripts/init.ipv6-global ]; then
233
		/etc/sysconfig/network-scripts/init.ipv6-global stop post
234
	fi
235
 
236
        rm -f /var/lock/subsys/network
237
        ;;
238
  status)
239
	echo $"Configured devices:"
240
	echo lo $interfaces
241
 
242
	echo $"Currently active devices:"
243
	echo $(/sbin/ip -o link show up | awk -F ": " '{ print $2 }')
244
	;;
245
  restart|reload|force-reload)
246
        cd "$CWD"
247
	$0 stop
248
	$0 start
249
	rc=$?
250
	;;
251
  *)
252
        echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"
253
        exit 2
254
esac
255
 
256
exit $rc