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