+defaultscripts = poweron-vm-default
+defaultscripts += poweroff-vm-default
+defaultscripts += suspend-vm-default
+defaultscripts += resume-vm-default
+
confdir = /etc/vmware-tools
conf_SCRIPTS = ./common/vm-support
-conf_SCRIPTS += ./common/poweron-vm-default
-conf_SCRIPTS += ./common/poweroff-vm-default
-conf_SCRIPTS += $(MODULES_OS)/suspend-vm-default
-conf_SCRIPTS += $(MODULES_OS)/resume-vm-default
+conf_SCRIPTS += ./common/statechange.subr
+conf_SCRIPTS += $(defaultscripts)
+
+vmwsrcdir = $(confdir)/scripts/vmware
+
+vmwsrc_SCRIPTS = $(MODULES_OS)/network
+
+$(defaultscripts): ./common/statechange.sh
+ cp $< $@
+++ /dev/null
-#!/bin/sh
-##########################################################
-# Copyright (C) 2001-2008 VMware, Inc. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published
-# by the Free Software Foundation version 2.1 and no later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
-# License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-##########################################################
-
-##########################################################################
-# DO NOT modify this file directly as it will be overwritten the next
-# time the VMware Tools are installed.
-##########################################################################
-
-echo `date` ": Executing '$0'"
-
-scriptsdir="`dirname $0`/scripts/`basename $0`.d"
-if [ -d "$scriptsdir" ]; then
- for scriptfile in "$scriptsdir"/*; do
- [ -x "$scriptfile" ] && "$scriptfile" poweroff-vm
- done
-fi
+++ /dev/null
-#!/bin/sh
-##########################################################
-# Copyright (C) 2001-2008 VMware, Inc. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published
-# by the Free Software Foundation version 2.1 and no later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
-# License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-##########################################################
-
-##########################################################################
-# DO NOT modify this file directly as it will be overwritten the next
-# time the VMware Tools are installed.
-##########################################################################
-
-echo `date` ": Executing '$0'"
-
-scriptsdir="`dirname $0`/scripts/`basename $0`.d"
-if [ -d "$scriptsdir" ]; then
- for scriptfile in "$scriptsdir"/*; do
- [ -x "$scriptfile" ] && "$scriptfile" poweron-vm
- done
-fi
-
--- /dev/null
+#!/bin/sh
+##########################################################
+# Copyright (C) 2010 VMware, Inc. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation version 2.1 and no later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
+# License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+##########################################################
+
+##########################################################################
+# DO NOT modify this file directly as it will be overwritten the next
+# time the VMware Tools are installed.
+##########################################################################
+
+#
+# statechange.sh
+#
+# This script is a refactored version of the legacy power scripts (e.g.,
+# poweron-vm-default). It expects to be installed in their places --
+# in other words, `basename "$0"` might be poweron-vm-default.
+#
+# Handy reference/shorthand used in this doc/scripts:
+# toolsConfDir ::= Depends on platform and installation settings. Likely
+# "/etc/vmware-tools" or
+# "/Library/Application Support/VMware Tools"
+# powerOp ::= One of "poweron-vm", "poweroff-vm", "suspend-vm", and
+# "resume-vm".
+# vmwScriptDir ::= $toolsConfDir/scripts/vmware
+# userScriptDir ::= $toolsConfDir/scripts/${powerOp}-default.d
+#
+# End users may install scripts of their own under $userScriptDir. They
+# are executed in alphabetical order with "$powerOp" as the only argument.
+#
+# NB: This directory layout remains to preserve backwards compatibility. End
+# users are free to write a single script which uses its only parameter
+# (${powerOp}) as a discriminator, and then install symlinks to it in each
+# of the ${powerOp}-default.d directories.
+#
+# On power-on and resume, VMware's scripts execute before the end user's. On
+# suspend and power-off, the end user's execute before VMware's. (This way,
+# VMware stops services only after the user's scripts have finished their
+# work, and conversely restores the same services before the user's scripts
+# attempt to use them.)
+#
+# Should any script exit non-zero, only its value will be saved to exitCode.
+# (Any further non-zero exits will have no effect on exitCode.) This script
+# exits with $exitCode.
+#
+# XXX Consider using the available/enabled pattern for VMware's scripts.
+#
+# XXX This should be staged as a single executable whereby the desired
+# power operation is passed in as a parameter. (I.e., one would run
+# "/path/to/statechange.sh suspend-vm" rather than having to install
+# statechange.sh as suspend-vm-default.)
+#
+
+echo `date` ": Executing '$0'"
+
+# See above.
+toolsConfDir=`dirname "$0"`
+
+# Pull in subroutines like Panic.
+. "$toolsConfDir"/statechange.subr
+
+
+#
+# RunScripts --
+#
+# Executes scripts installed under $scriptDir.
+#
+# Side effects:
+# exitCode may be incremented.
+#
+
+RunScripts() {
+ scriptDir="$1"
+
+ if [ -d "$scriptDir" ]; then
+ for scriptFile in "$scriptDir"/*; do
+ if [ -x "$scriptFile" ]; then
+ "$scriptFile" $powerOp
+ exitCode=`expr $exitCode \| $?`
+ fi
+ done
+ fi
+}
+
+
+#
+# main --
+#
+# Entry point. See comments at top of file for details.
+#
+# Results:
+# Exits with $exitCode.
+#
+
+main() {
+ # This is sanity checked in the case/esac bit below.
+ powerOp=`basename "$0" | sed 's,-default,,'`
+ exitCode=0
+
+ vmwScriptDir="$toolsConfDir/scripts/vmware"
+ userScriptDir="$toolsConfDir/scripts/${powerOp}-default.d"
+
+ case "$powerOp" in
+ poweron-vm|resume-vm)
+ RunScripts "$vmwScriptDir"
+ RunScripts "$userScriptDir"
+ ;;
+ poweroff-vm|suspend-vm)
+ RunScripts "$userScriptDir"
+ RunScripts "$vmwScriptDir"
+ ;;
+ *)
+ Panic "Invalid argument: $powerOp"
+ ;;
+ esac
+
+ return $exitCode
+}
+
+main
#!/bin/sh
##########################################################
-# Copyright (C) 2004-2008 VMware, Inc. All rights reserved.
+# Copyright (C) 2010 VMware, Inc. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published
# time the VMware Tools are installed.
##########################################################################
-echo `date` ": Executing '$0'"
-echo
-# Start the network.
-/etc/netstart
+#
+# Panic --
+#
+# Write a formatted error message to stderr and exit.
+#
+# Results:
+# Stderr is spammed, program exits with exit code 1.
+#
+# Side effects:
+# None.
+#
-scriptsdir="`dirname $0`/scripts/`basename $0`.d"
-if [ -d "$scriptsdir" ]; then
- for scriptfile in "$scriptsdir"/*; do
- [ -x "$scriptfile" ] && "$scriptfile" resume-vm
- done
-fi
+Panic() {
+ fmt="`date '+%b %d %H:%M:%S'` `basename \"$0\"`"
+ if [ -n "$1" ]; then
+ fmt="${fmt}: $1"
+ shift
+ fi
+ printf >&2 "${fmt}\n" "$@"
+ exit 1
+}
--- /dev/null
+#!/bin/sh
+##########################################################
+# Copyright (C) 2010 VMware, Inc. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation version 2.1 and no later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
+# License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+##########################################################
+
+##########################################################################
+# DO NOT modify this file directly as it will be overwritten the next
+# time the VMware Tools are installed.
+##########################################################################
+
+#
+# network (FreeBSD 6.3 and above)
+#
+# This script uses FreeBSD's rc(8) scripts to stop and restart networking
+# services in response to suspend and resume events, respectively.
+#
+
+
+echo `date` ": Executing '$0'"
+echo
+
+. `dirname "$0"`/../../statechange.subr
+
+
+#
+# ToggleNetwork --
+#
+# Sources native configuration files in a subshell and executes native
+# scripts to either start or stop networking services associated with
+# a single interface.
+#
+# Results:
+# See description above.
+#
+# Side effects:
+# All side effects implied by FreeBSD's netif script.
+#
+
+ToggleNetwork() {
+ (
+ . /etc/rc.subr
+ . /etc/network.subr
+
+ load_rc_config network
+
+ for intf in `list_net_interfaces dhcp`; do
+ /etc/rc.d/netif $1 $intf
+ ec=$?
+
+ # Failure to stop an interface should not interfere with suspend.
+ if [ "$1" != "stop" ]; then
+ exitCode=`expr $exitCode \| $ec`
+ fi
+ done
+ )
+}
+
+
+#
+# main --
+#
+# Main entry point. Perform some sanity checking, then map state change
+# events to relevant networking operations.
+#
+# Results:
+# See comment at top of file.
+#
+
+main() {
+ exitCode=0
+
+ [ -r /etc/rc.subr ] || Panic "Cannot read /etc/rc.subr."
+ [ -r /etc/network.subr ] || Panic "Cannot read /etc/network.subr"
+ [ -x /etc/rc.d/netif ] || Panic "Cannot read /etc/rc.d/netif"
+
+ case "$1" in
+ suspend-vm)
+ ToggleNetwork stop
+ ;;
+ resume-vm)
+ ToggleNetwork start
+ ;;
+ *) ;;
+ esac
+
+ return $exitCode
+}
+
+main "$@"
+++ /dev/null
-#!/bin/sh
-##########################################################
-# Copyright (C) 2004-2008 VMware, Inc. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published
-# by the Free Software Foundation version 2.1 and no later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
-# License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-##########################################################
-
-##########################################################################
-# DO NOT modify this file directly as it will be overwritten the next
-# time the VMware Tools are installed.
-##########################################################################
-
-echo `date` ": Executing '$0'"
-echo
-
-scriptsdir="`dirname $0`/scripts/`basename $0`.d"
-if [ -d "$scriptsdir" ]; then
- for scriptfile in "$scriptsdir"/*; do
- [ -x "$scriptfile" ] && "$scriptfile" suspend-vm
- done
-fi
-
-# Release the IP if DHCP is used.
-for intf in `pgrep -fl dhclient | cut -d" " -f3 | sort | uniq`; do
- if [ -x /etc/rc.d/netif ]; then
- /etc/rc.d/netif stop "$intf"
- else
- ifconfig "$intf" down
- ifconfig "$intf" delete
- fi
-done
--- /dev/null
+#!/bin/sh
+##########################################################
+# Copyright (C) 2001-2010 VMware, Inc. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation version 2.1 and no later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
+# License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+##########################################################
+
+
+#
+# network (Linux)
+#
+# Using a combination of a system networking script, ifconfig, and ifup,
+# attempt to release and renew DHCP leases upon receipt of suspend and resume
+# events, respectively.
+#
+
+
+echo `date` ": Executing '$0'"
+echo
+
+. `dirname "$0"`/../../statechange.subr
+
+
+#
+# find_networking_script --
+#
+# Searches common Linux distro init/rc paths to find a singular network
+# services script.
+#
+# Result:
+# Returns a valid networking script path on success or "error" on failure.
+#
+# Side effects:
+# None.
+#
+
+find_networking_script() {
+ local script="error"
+ for dir in "/etc/init.d" "/sbin/init.d" "/etc" "/etc/rc.d" ; do
+ if [ -d "$dir/rc0.d" ] &&
+ [ -d "$dir/rc1.d" ] &&
+ [ -d "$dir/rc2.d" ] &&
+ [ -d "$dir/rc3.d" ] &&
+ [ -d "$dir/rc4.d" ] &&
+ [ -d "$dir/rc5.d" ] &&
+ [ -d "$dir/rc6.d" ]; then
+
+ # Now find the appropriate networking script.
+ if [ -d "$dir/init.d" ]; then
+ if [ -x "$dir/init.d/network" ]; then
+ script="$dir/init.d/network"
+ elif [ -x "$dir/init.d/networking" ]; then
+ script="$dir/init.d/networking"
+ fi
+ else
+ if [ -x "$dir/network" ]; then
+ script="$dir/network"
+ elif [ -x "$dir/networking" ]; then
+ script="$dir/networking"
+ fi
+ fi
+ fi
+ done
+
+ echo "$script"
+}
+
+
+#
+# save_active_NIC_list --
+#
+# Records a list of every active NIC to /var/run/vmware-active-nics.
+#
+# XXX What's the story on aliases? Should they still be included, or will
+# they be recreated automatically upon resume?
+#
+# Results:
+# $activeList has, one per line, a list of all active NICs.
+#
+# Side effects:
+# None.
+#
+
+save_active_NIC_list() {
+ >$activeList
+
+ for nic in `ifconfig | awk '/^eth/ { print $1 }'`; do
+ ifconfig $nic | egrep -q '\bUP\b' && echo $nic >> $activeList
+ exitCode=`expr $exitCode \| $?`
+ done
+}
+
+
+#
+# rescue_NIC --
+#
+# For each NIC recorded in $activeList that is not currently "up", run
+# "ifup $nic".
+#
+# Results:
+# All downed NICs should be active.
+#
+
+rescue_NIC() {
+ if [ -f "$activeList" ]; then
+ while read nic; do
+ if ifconfig $nic | egrep -q '\bUP\b'; then
+ echo `date` "[rescue_nic] $nic is already active."
+ else
+ echo `date` "[rescue_nic] activating $nic ..."
+
+ ifup $nic
+ exitCode=`expr $exitCode \| $?`
+ fi
+ done < $activeList
+
+ rm -f $activeList
+ fi
+}
+
+
+#
+# TranquilizeNetworkManager --
+#
+# Put the NetworkManager daemon to sleep (maybe).
+#
+# See http://projects.gnome.org/NetworkManager/developers/spec.html .
+#
+# Results:
+# Sleep(true) request is sent to the NetworkManager D-Bus interface.
+#
+# Side effects:
+# None.
+#
+
+TranquilizeNetworkManager() {
+ # `which' may be a bit noisy, so we'll shush it.
+ dbusSend=`which dbus-send 2>/dev/null`
+ if [ $? -eq 0 ]; then
+ # NetworkManager 0.6
+ $dbusSend --system --dest=org.freedesktop.NetworkManager \
+ /org/freedesktop/NetworkManager \
+ org.freedesktop.NetworkManager.sleep
+ # NetworkManager 0.7.0
+ $dbusSend --system --dest=org.freedesktop.NetworkManager \
+ /org/freedesktop/NetworkManager \
+ org.freedesktop.NetworkManager.Sleep boolean:true
+ fi
+}
+
+
+#
+# WakeNetworkManager --
+#
+# Wake the NetworkManager daemon (maybe).
+#
+# See http://projects.gnome.org/NetworkManager/developers/spec.html .
+#
+# Results:
+# Sleep(false)request is sent to the NetworkManager D-Bus interface.
+#
+# Side effects:
+# None.
+#
+
+WakeNetworkManager() {
+ # `which' may be a bit noisy, so we'll shush it.
+ dbusSend=`which dbus-send 2>/dev/null`
+ if [ $? -eq 0 ]; then
+ # NetworkManager 0.6
+ $dbusSend --system --dest=org.freedesktop.NetworkManager \
+ /org/freedesktop/NetworkManager \
+ org.freedesktop.NetworkManager.wake
+ # NetworkManager 0.7.0
+ $dbusSend --system --dest=org.freedesktop.NetworkManager \
+ /org/freedesktop/NetworkManager \
+ org.freedesktop.NetworkManager.Sleep boolean:false
+ fi
+}
+
+
+#
+# main --
+#
+# Main entry point. Perform some sanity checking, then map state change
+# events to relevant networking operations.
+#
+# Results:
+# See comment at top of file.
+#
+
+main() {
+ exitCode=0
+ activeList=/var/run/vmware-active-nics
+
+ networkScript=`find_networking_script`
+ [ "$networkScript" != "error" ] || Panic "Cannot find system networking script."
+
+ # XXX Are these really necessary? If so, we should have seen customer
+ # complaints by now.
+ which ifup >/dev/null 2>&1 || Panic "ifup not in search path."
+ which ifconfig >/dev/null 2>&1 || Panic "ifconfig not in search path."
+
+ case "$1" in
+ poweron-vm)
+ rm -f $activeList
+ ;;
+ suspend-vm)
+ save_active_NIC_list
+ "$networkScript" stop
+ TranquilizeNetworkManager
+ ;;
+ resume-vm)
+ # According to hfu, "/etc/init.d/networking restart" on Debian 5.0
+ # may bring down ethernet interfaces tagged as "allow-hotplug" without
+ # bringing them back up.
+ #
+ # This is especially a problem when reverting to a live, running
+ # VM snapshot where an active NIC list hadn't yet been generated,
+ # resulting in sudden loss of an otherwise operational NIC.
+ #
+ # So, if the active list doesn't exist, assume we're coming back to
+ # a live snapshot and capture the current active list now for
+ # rescue later.
+ if [ ! -s $activeList ]; then
+ save_active_NIC_list
+ fi
+ WakeNetworkManager
+ # XXX Do we really want restart or is start sufficient? Like, would
+ # using start avoid the problem mentioned above?
+ "$networkScript" restart
+ rescue_NIC
+ ;;
+ *) ;;
+ esac
+
+ return $exitCode
+}
+
+main "$@"
+++ /dev/null
-#!/bin/sh
-##########################################################
-# Copyright (C) 2001-2008 VMware, Inc. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published
-# by the Free Software Foundation version 2.1 and no later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
-# License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-##########################################################
-
-##########################################################################
-# DO NOT modify this file directly as it will be overwritten the next
-# time the VMware Tools are installed.
-##########################################################################
-
-echo `date` ": Executing '$0'"
-echo
-
-find_networking_script() {
- local script="error"
- for dir in "/etc/init.d" "/sbin/init.d" "/etc" "/etc/rc.d" ; do
- if [ -d "$dir/rc0.d" ] &&
- [ -d "$dir/rc1.d" ] &&
- [ -d "$dir/rc2.d" ] &&
- [ -d "$dir/rc3.d" ] &&
- [ -d "$dir/rc4.d" ] &&
- [ -d "$dir/rc5.d" ] &&
- [ -d "$dir/rc6.d" ]; then
-
- # Now find the appropriate networking script.
- if [ -d "$dir/init.d" ]; then
- if [ -x "$dir/init.d/network" ]; then
- script="$dir/init.d/network"
- elif [ -x "$dir/init.d/networking" ]; then
- script="$dir/init.d/networking"
- fi
- else
- if [ -x "$dir/network" ]; then
- script="$dir/network"
- elif [ -x "$dir/networking" ]; then
- script="$dir/networking"
- fi
- fi
- fi
- done
-
- echo "$script"
-}
-
-save_active_NIC_list() {
- ifconfig_path=`which ifconfig 2>/dev/null`
- if [ $? ]; then
- # Add nic to the list only if it is not already there,
- # since suspend-vm-default might already create the list.
- "$ifconfig_path" | grep '^[^[:space:]]' | awk '{ print $1 }' | \
- while read nic; do
- if ! grep -q "$nic" /var/run/vmware-active-nics 2>/dev/null; then
- echo "$nic" >> /var/run/vmware-active-nics
- fi
- done
- fi
-}
-
-rescue_NIC() {
- niclist="/var/run/vmware-active-nics"
-
- ifup_path=`which ifup 2>/dev/null`;
- if [ $? -ne 0 ]; then
- return 1;
- fi
-
- ifconfig_path=`which ifconfig 2>/dev/null`;
- if [ $? -ne 0 ]; then
- return 1;
- fi
-
- if [ -f "$niclist" ]; then
- while read nic; do
- if $ifconfig_path $nic | egrep '^ +UP ' >/dev/null 2>&1; then
- echo `date` "[resume-vm-default::rescue_nic] $nic is already active."
- else
- echo `date` "[rescue_nic] activating $nic ..."
-
- $ifup_path $nic
- fi
- done < $niclist
-
- rm -f $niclist
- fi
-}
-
-
-#
-# wakeNetworkManager --
-#
-# Wake the NetworkManager daemon (maybe).
-#
-# See http://projects.gnome.org/NetworkManager/developers/spec.html .
-#
-# Results:
-# Sleep(false)request is sent to the NetworkManager D-Bus interface.
-#
-# Side effects:
-# None.
-#
-
-wakeNetworkManager() {
- # `which' may be a bit noisy, so we'll shush it.
- dbusSend=`which dbus-send 2>/dev/null`
- if [ $? -eq 0 ]; then
- # NetworkManager 0.6
- $dbusSend --system --dest=org.freedesktop.NetworkManager \
- /org/freedesktop/NetworkManager \
- org.freedesktop.NetworkManager.wake
- # NetworkManager 0.7.0
- $dbusSend --system --dest=org.freedesktop.NetworkManager \
- /org/freedesktop/NetworkManager \
- org.freedesktop.NetworkManager.Sleep boolean:false
- fi
-}
-
-
-#
-# main
-#
-
-# Save nic list for later rescue, or we might lose the active nic after
-# calling '/etc/init.d/networking restart'.
-save_active_NIC_list
-
-wakeNetworkManager
-
-network=`find_networking_script`
-if [ "$network" != "error" ]; then
- "$network" restart
- # Continue even if the networking init script wasn't successful.
- status=0
-else
- echo "networking script not found"
- status=1
-fi
-
-if [ $status -eq 0 ]; then
- rescue_NIC
-fi
-
-scriptsdir="`dirname $0`/scripts/`basename $0`.d"
-if [ -d "$scriptsdir" ]; then
- for scriptfile in "$scriptsdir"/*; do
- [ -x "$scriptfile" ] && "$scriptfile" resume-vm
- done
-fi
-
-exit "$status"
+++ /dev/null
-#!/bin/sh
-##########################################################
-# Copyright (C) 2001-2008 VMware, Inc. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published
-# by the Free Software Foundation version 2.1 and no later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
-# License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-##########################################################
-
-##########################################################################
-# DO NOT modify this file directly as it will be overwritten the next
-# time the VMware Tools are installed.
-##########################################################################
-
-echo `date` ": Executing '$0'"
-echo
-
-find_networking_script() {
- local script="error"
- for dir in "/etc/init.d" "/sbin/init.d" "/etc" "/etc/rc.d" ; do
- if [ -d "$dir/rc0.d" ] &&
- [ -d "$dir/rc1.d" ] &&
- [ -d "$dir/rc2.d" ] &&
- [ -d "$dir/rc3.d" ] &&
- [ -d "$dir/rc4.d" ] &&
- [ -d "$dir/rc5.d" ] &&
- [ -d "$dir/rc6.d" ]; then
-
- # Now find the appropriate networking script.
- if [ -d "$dir/init.d" ]; then
- if [ -x "$dir/init.d/network" ]; then
- script="$dir/init.d/network"
- elif [ -x "$dir/init.d/networking" ]; then
- script="$dir/init.d/networking"
- fi
- else
- if [ -x "$dir/network" ]; then
- script="$dir/network"
- elif [ -x "$dir/networking" ]; then
- script="$dir/networking"
- fi
- fi
- fi
- done
-
- echo "$script"
-}
-
-save_active_NIC_list() {
- ifconfig_path=`which ifconfig 2>/dev/null`
- if [ $? ]; then
- "$ifconfig_path" | grep '^[^[:space:]]' | awk '{ print $1 }' > /var/run/vmware-active-nics
- fi
-}
-
-
-#
-# tranquilizeNetworkManager --
-#
-# Put the NetworkManager daemon to sleep (maybe).
-#
-# See http://projects.gnome.org/NetworkManager/developers/spec.html .
-#
-# Results:
-# Sleep(true) request is sent to the NetworkManager D-Bus interface.
-#
-# Side effects:
-# None.
-#
-
-tranquilizeNetworkManager() {
- # `which' may be a bit noisy, so we'll shush it.
- dbusSend=`which dbus-send 2>/dev/null`
- if [ $? -eq 0 ]; then
- # NetworkManager 0.6
- $dbusSend --system --dest=org.freedesktop.NetworkManager \
- /org/freedesktop/NetworkManager \
- org.freedesktop.NetworkManager.sleep
- # NetworkManager 0.7.0
- $dbusSend --system --dest=org.freedesktop.NetworkManager \
- /org/freedesktop/NetworkManager \
- org.freedesktop.NetworkManager.Sleep boolean:true
- fi
-}
-
-
-#
-# main
-#
-
-scriptsdir="`dirname $0`/scripts/`basename $0`.d"
-if [ -d "$scriptsdir" ]; then
- for scriptfile in "$scriptsdir"/*; do
- [ -x "$scriptfile" ] && "$scriptfile" suspend-vm
- done
-fi
-
-save_active_NIC_list
-
-network=`find_networking_script`
-if [ "$network" != "error" ]; then
- "$network" stop
- # If the network is down, this may fail but that's not a good reason
- # to prevent the suspend.
- status=0
-else
- echo "networking script not found"
- status=1
-fi
-
-tranquilizeNetworkManager
-
-exit "$status"
--- /dev/null
+#!/bin/sh
+##########################################################
+# Copyright (C) 2006-2010 VMware, Inc. All rights reserved.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published
+# by the Free Software Foundation version 2.1 and no later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
+# License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+##########################################################
+
+##########################################################################
+# DO NOT modify this file directly as it will be overwritten the next
+# time the VMware Tools are installed.
+##########################################################################
+
+#
+# network (Solaris 10+)
+#
+# Solaris's ifconfig conveniently handles DHCP arguments directly, so we
+# may use it to release and renew DHCP leases upon receipt of suspend
+# and resume events, respectively.
+#
+
+
+echo `date` ": Executing '$0'"
+echo
+
+
+#
+# main --
+#
+# Script entry point.
+#
+# Results:
+#
+# Side effects:
+#
+
+main() {
+ activeList=/var/run/vmware-active-nics
+ exitCode=0
+
+ case "$1" in
+ poweron-vm)
+ rm -f $activeList
+ ;;
+ suspend-vm)
+ >$activeList
+
+ # Release DHCP addresses and note each interface in our active list
+ # so it can be brought back up on resume
+ for nic in `ifconfig -a | awk -F: '/DHCP/ { print $1; }'`; do
+ # Sometimes interfaces will claim DHCP and not actually be "under
+ # DHCP control". Let's double check the status to ensure this
+ # isn't the case.
+ if ifconfig "$nic" dhcp status > /dev/null 2>&1; then
+ echo "$0: releasing DHCP address for $nic"
+ echo "$nic" >> $activeList
+ ifconfig "$nic" dhcp release
+ fi
+ done
+ ;;
+ resume-vm)
+ if [ -s $activeList ]; then
+ while read nic; do
+ echo "$0: bringing up DHCP on $nic"
+ ifconfig "$nic" dhcp
+ exitCode=`expr $exitCode \| $?`
+ done < $activeList
+ fi
+ ;;
+ *)
+ ;;
+ esac
+
+ return $exitCode
+}
+
+main "$@"
+++ /dev/null
-#!/bin/sh
-##########################################################
-# Copyright (C) 2006-2008 VMware, Inc. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published
-# by the Free Software Foundation version 2.1 and no later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
-# License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-##########################################################
-
-##########################################################################
-# DO NOT modify this file directly as it will be overwritten the next
-# time the VMware Tools are installed.
-##########################################################################
-
-echo `date` ": Executing '$0'"
-echo
-
-ACTIVELIST=/var/run/vmware-active-nics
-
-if [ -f $ACTIVELIST ] ; then
- for i in `cat $ACTIVELIST`; do
- echo "$0: bringing up DHCP on $i"
- ifconfig $i dhcp
- done
- rm $ACTIVELIST
-fi
-
-scriptsdir="`dirname $0`/scripts/`basename $0`.d"
-if [ -d "$scriptsdir" ]; then
- for scriptfile in "$scriptsdir"/*; do
- [ -x "$scriptfile" ] && "$scriptfile" resume-vm
- done
-fi
-
+++ /dev/null
-#!/bin/sh
-##########################################################
-# Copyright (C) 2006-2008 VMware, Inc. All rights reserved.
-#
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU Lesser General Public License as published
-# by the Free Software Foundation version 2.1 and no later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
-# License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-##########################################################
-
-##########################################################################
-# DO NOT modify this file directly as it will be overwritten the next
-# time the VMware Tools are installed.
-##########################################################################
-
-echo `date` ": Executing '$0'"
-echo
-
-scriptsdir="`dirname $0`/scripts/`basename $0`.d"
-if [ -d "$scriptsdir" ]; then
- for scriptfile in "$scriptsdir"/*; do
- [ -x "$scriptfile" ] && "$scriptfile" suspend-vm
- done
-fi
-
-ACTIVELIST=/var/run/vmware-active-nics
-
-> $ACTIVELIST
-
-# Release DHCP addresses and note each interface in our
-# active list so it can be brought back up on resume
-for i in `ifconfig -a | grep DHCP | cut -f1 -d:`; do
- # Sometimes interfaces will claim DHCP and not actually be "under DHCP
- # control". Let's double check the status to ensure this isn't the case.
- if ifconfig "$i" dhcp status > /dev/null 2>&1; then
- echo "$0: releasing DHCP address for $i"
- echo "$i" >> $ACTIVELIST
- ifconfig "$i" dhcp release
- fi
-done