rev |
line source |
nneul@18391
|
1 #!/bin/sh
|
nneul@18391
|
2 ##########################################################
|
nneul@18391
|
3 # Copyright (C) 2001-2010 VMware, Inc. All rights reserved.
|
nneul@18391
|
4 #
|
nneul@18391
|
5 # This program is free software; you can redistribute it and/or modify it
|
nneul@18391
|
6 # under the terms of the GNU Lesser General Public License as published
|
nneul@18391
|
7 # by the Free Software Foundation version 2.1 and no later version.
|
nneul@18391
|
8 #
|
nneul@18391
|
9 # This program is distributed in the hope that it will be useful, but
|
nneul@18391
|
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
nneul@18391
|
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
|
nneul@18391
|
12 # License for more details.
|
nneul@18391
|
13 #
|
nneul@18391
|
14 # You should have received a copy of the GNU Lesser General Public License
|
nneul@18391
|
15 # along with this program; if not, write to the Free Software Foundation, Inc.,
|
nneul@18391
|
16 # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
nneul@18391
|
17 #
|
nneul@18391
|
18 ##########################################################
|
nneul@18391
|
19
|
nneul@18391
|
20
|
nneul@18391
|
21 #
|
nneul@18391
|
22 # network (Linux)
|
nneul@18391
|
23 #
|
nneul@18391
|
24 # Using a combination of a system networking script, ifconfig, and ifup,
|
nneul@18391
|
25 # attempt to release and renew DHCP leases upon receipt of suspend and resume
|
nneul@18391
|
26 # events, respectively.
|
nneul@18391
|
27 #
|
nneul@18391
|
28
|
nneul@18391
|
29
|
nneul@18391
|
30 echo `date` ": Executing '$0'"
|
nneul@18391
|
31 echo
|
nneul@18391
|
32
|
nneul@18391
|
33 . `dirname "$0"`/../../statechange.subr
|
nneul@18391
|
34
|
nneul@18391
|
35
|
nneul@18391
|
36 #
|
nneul@18391
|
37 # find_networking_script --
|
nneul@18391
|
38 #
|
nneul@18391
|
39 # Searches common Linux distro init/rc paths to find a singular network
|
nneul@18391
|
40 # services script.
|
nneul@18391
|
41 #
|
nneul@18391
|
42 # Result:
|
nneul@18391
|
43 # Returns a valid networking script path on success or "error" on failure.
|
nneul@18391
|
44 #
|
nneul@18391
|
45 # Side effects:
|
nneul@18391
|
46 # None.
|
nneul@18391
|
47 #
|
nneul@18391
|
48
|
nneul@18391
|
49 find_networking_script() {
|
nneul@18391
|
50 echo "network.sh"
|
nneul@18391
|
51 }
|
nneul@18391
|
52
|
nneul@18391
|
53
|
nneul@18391
|
54 #
|
nneul@18391
|
55 # run_network_script --
|
nneul@18391
|
56 #
|
nneul@18391
|
57 # Finds out how to run the system's script used to control networking, and
|
nneul@18391
|
58 # runs it with the given argument (which should be one of the usual SysV
|
nneul@18391
|
59 # init script arguments).
|
nneul@18391
|
60 #
|
nneul@18391
|
61 run_network_script()
|
nneul@18391
|
62 {
|
nneul@18391
|
63 script=`find_networking_script`
|
nneul@18391
|
64 [ "$script" != "error" ] || Panic "Cannot find system networking script."
|
nneul@18391
|
65
|
nneul@18391
|
66 "$script" "$1"
|
nneul@18391
|
67 }
|
nneul@18391
|
68
|
nneul@18391
|
69
|
nneul@18391
|
70 #
|
nneul@18391
|
71 # save_active_NIC_list --
|
nneul@18391
|
72 #
|
nneul@18391
|
73 # Records a list of every active NIC to /var/run/vmware-active-nics.
|
nneul@18391
|
74 #
|
nneul@18391
|
75 # XXX What's the story on aliases? Should they still be included, or will
|
nneul@18391
|
76 # they be recreated automatically upon resume?
|
nneul@18391
|
77 #
|
nneul@18391
|
78 # Results:
|
nneul@18391
|
79 # $activeList has, one per line, a list of all active NICs.
|
nneul@18391
|
80 #
|
nneul@18391
|
81 # Side effects:
|
nneul@18391
|
82 # None.
|
nneul@18391
|
83 #
|
nneul@18391
|
84
|
nneul@18391
|
85 save_active_NIC_list() {
|
nneul@18391
|
86 >$activeList
|
nneul@18391
|
87
|
nneul@18391
|
88 for nic in `ifconfig | awk '/^eth/ { print $1 }'`; do
|
nneul@18391
|
89 ifconfig $nic | egrep -q '\bUP\b' && echo $nic >> $activeList
|
nneul@18391
|
90 exitCode=`expr $exitCode \| $?`
|
nneul@18391
|
91 done
|
nneul@18391
|
92 }
|
nneul@18391
|
93
|
nneul@18391
|
94
|
nneul@18391
|
95 #
|
nneul@18391
|
96 # rescue_NIC --
|
nneul@18391
|
97 #
|
nneul@18391
|
98 # For each NIC recorded in $activeList that is not currently "up", run
|
nneul@18391
|
99 # "INTERFACE=$nic network.sh start".
|
nneul@18391
|
100 #
|
nneul@18391
|
101 # Results:
|
nneul@18391
|
102 # All downed NICs should be active.
|
nneul@18391
|
103 #
|
nneul@18391
|
104
|
nneul@18391
|
105 rescue_NIC() {
|
nneul@18391
|
106 if [ -f "$activeList" ]; then
|
nneul@18391
|
107 while read nic; do
|
nneul@18391
|
108 if ifconfig $nic | egrep -q '\bUP\b'; then
|
nneul@18391
|
109 echo `date` "[rescue_nic] $nic is already active."
|
nneul@18391
|
110 else
|
nneul@18391
|
111 echo `date` "[rescue_nic] activating $nic ..."
|
nneul@18391
|
112
|
nneul@18391
|
113 INTERFACE=$nic /etc/init.d/network.sh start
|
nneul@18391
|
114 exitCode=`expr $exitCode \| $?`
|
nneul@18391
|
115 fi
|
nneul@18391
|
116 done < $activeList
|
nneul@18391
|
117
|
nneul@18391
|
118 rm -f $activeList
|
nneul@18391
|
119 fi
|
nneul@18391
|
120 }
|
nneul@18391
|
121
|
nneul@18391
|
122
|
nneul@18391
|
123 #
|
nneul@18391
|
124 # main --
|
nneul@18391
|
125 #
|
nneul@18391
|
126 # Main entry point. Perform some sanity checking, then map state change
|
nneul@18391
|
127 # events to relevant networking operations.
|
nneul@18391
|
128 #
|
nneul@18391
|
129 # Results:
|
nneul@18391
|
130 # See comment at top of file.
|
nneul@18391
|
131 #
|
nneul@18391
|
132
|
nneul@18391
|
133 main() {
|
nneul@18391
|
134 exitCode=0
|
nneul@18391
|
135 activeList=/var/run/vmware-active-nics
|
nneul@18391
|
136
|
nneul@18391
|
137 # XXX Are these really necessary? If so, we should have seen customer
|
nneul@18391
|
138 # complaints by now.
|
nneul@18391
|
139 which ifconfig >/dev/null 2>&1 || Panic "ifconfig not in search path."
|
nneul@18391
|
140
|
nneul@18391
|
141 case "$1" in
|
nneul@18391
|
142 poweron-vm)
|
nneul@18391
|
143 rm -f $activeList
|
nneul@18391
|
144 ;;
|
nneul@18391
|
145 suspend-vm)
|
nneul@18391
|
146 exitCode=$?
|
nneul@18391
|
147 if [ $exitCode != 0 ]; then
|
nneul@18391
|
148 save_active_NIC_list
|
nneul@18391
|
149 run_network_script stop
|
nneul@18391
|
150 exitCode=$?
|
nneul@18391
|
151 fi
|
nneul@18391
|
152 ;;
|
nneul@18391
|
153 resume-vm)
|
nneul@18391
|
154 WakeNetworkManager
|
nneul@18391
|
155 exitCode=$?
|
nneul@18391
|
156 if [ $exitCode != 0 ]; then
|
nneul@18391
|
157 # According to hfu, "/etc/init.d/networking restart" on Debian 5.0
|
nneul@18391
|
158 # may bring down ethernet interfaces tagged as "allow-hotplug" without
|
nneul@18391
|
159 # bringing them back up.
|
nneul@18391
|
160 #
|
nneul@18391
|
161 # This is especially a problem when reverting to a live, running
|
nneul@18391
|
162 # VM snapshot where an active NIC list hadn't yet been generated,
|
nneul@18391
|
163 # resulting in sudden loss of an otherwise operational NIC.
|
nneul@18391
|
164 #
|
nneul@18391
|
165 # So, if the active list doesn't exist, assume we're coming back to
|
nneul@18391
|
166 # a live snapshot and capture the current active list now for
|
nneul@18391
|
167 # rescue later.
|
nneul@18391
|
168 if [ ! -s $activeList ]; then
|
nneul@18391
|
169 save_active_NIC_list
|
nneul@18391
|
170 fi
|
nneul@18391
|
171
|
nneul@18391
|
172 # We shall use start not restart here. Otherwise we may not be able
|
nneul@18391
|
173 # to bring back active list on distros like sles11sp2
|
nneul@18391
|
174 # -- PR 816791
|
nneul@18391
|
175 run_network_script start
|
nneul@18391
|
176 rescue_NIC
|
nneul@18391
|
177 exitCode=$?
|
nneul@18391
|
178 fi
|
nneul@18391
|
179 ;;
|
nneul@18391
|
180 *) ;;
|
nneul@18391
|
181 esac
|
nneul@18391
|
182
|
nneul@18391
|
183 return $exitCode
|
nneul@18391
|
184 }
|
nneul@18391
|
185
|
nneul@18391
|
186 main "$@"
|