[ncolug] Re: vm

  • From: larry <larry@xxxxxxxxxxxx>
  • To: ncolug@xxxxxxxxxxxxx
  • Date: Fri, 23 Nov 2007 10:49:16 -0500

Yes, it could. Does it?

It could also balance my checkbook.

Chuck Stickelman wrote:
What do you want to trigger it?

The Linux Hypervisor could run the apcd daemon and initiate the shutdown when 
the UPS's batteries are low...

Chuck


-----Original Message-----
From: "larry" <larry@xxxxxxxxxxxx>
To: "ncolug@xxxxxxxxxxxxx" <ncolug@xxxxxxxxxxxxx>
Sent: 11/23/2007 9:56 AM
Subject: [ncolug] Re: vm

Very nice. But essentially this is just a shutdown command. What will trigger it to run?

Jim Willeke wrote:
For VMWare this script should work.

#####################################################################
#!/bin/sh
#
#  UPS shutdown script for VMware ESX 3.0
#
#####################################################################
# set the paths that the vmware tools need
PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin"


#####################################################################
# try do a nice shutdown of VM there is power
count_vm_on=0
for vm in `vmware-cmd -l` ; do
  #echo "VM: " $vm
  for VMstate in `vmware-cmd "$vm" getstate` ; do
  #echo $VMstate

  # If the VM is power ON
  if [ $VMstate = "on" ] ; then
     echo " "
     echo "VM: " $vm
     echo "State: is on and will now tell it to shut down"
     echo "Shutting down: " $vm
     vmware-cmd "$vm" stop trysoft
     vmwarecmd_exitcode=$(expr $?)
     if [ $vmwarecmd_exitcode -ne 0 ] ; then
         echo "exitcode: $vmwarecmd_exitcode so will now turn it off hard"
         vmware-cmd "$vm" stop hard
     fi
     count_vm_on=$count_vm_on+1
    sleep 2
  # if the VM is power OFF
  elif [ $VMstate = "off" ] ; then
     echo " "
     echo "VM: " $vm
     echo "State: is off, so i skip it"
  # if the VM is power suspended
  elif [ $VMstate = "suspended" ] ; then
     echo " "
     echo "VM: " $vm
     echo "State: is suspended, so i skip it"
  # if state is getstate or =
  else
     printf ""
    #echo "unknown state: " $VMstate
  fi

  done
done


########################################################################
# wait for up to 5 min for the VM to shutd
#
if [ $count_vm_on = 0 ] ; then
  echo " "
  echo "All VM is off or suspended"
else
  echo " "
  vm_time_out=300
  count_vm_on=0
  echo "Waiting for VMware virtual machines."
  for (( second=0; second<$vm_time_out; second=second+5 )); do
     sleep 5
     printf "."
     count_vm_on=0
     for vm in `vmware-cmd -l` ; do
        for VMstate in `vmware-cmd "$vm" getstate` ; do
        if [ $VMstate = "on" ] ; then
           count_vm_on=$(expr $count_vm_on + 1)
        fi
     done
  done
  if [ $count_vm_on = 0 ] ; then
     #echo "exit for"
     break
  fi
  done
  #echo $VMstate
fi
#echo $count_vm_on


#####################################################################
# checking if all the VM are off and if not then turn them off
for vm in `vmware-cmd -l` ; do
  #echo "VM: " $vm
  for VMstate in `vmware-cmd "$vm" getstate` ; do
    # If the VM is power ON
    if [ $VMstate = "on" ] ; then
      echo " "
      echo "Found this VM: " $vm
      echo "it is stille on but now i will turn it off"
      vmware-cmd "$vm" stop hard
      sleep 2
    fi
  done
done
#####################################################################
# Will now shutdown the ESX server as all VM are now off
echo " "
echo "now all VM is down, so will shutdown ESX host now"
echo " "
shutdown -h now


-jim
Phone: 419.564.7692
Email: jim@xxxxxxxxxxx
IM: jim@xxxxxxxxxxx (on MSN)
IM: jwilleke@xxxxxxxxx (on GOOGLE)
IM: jwilleke (on Yahoo)
IM: jeemster (on AIM)
My LinkedIn: http://www.linkedin.com/in/jwilleke


larry wrote:
No, the guests do NOT "shut down cleanly" just because you stopped or shut down the hypervisor.

You want to talk about "standards" in regard to UPS signaling behaviour?! Which of the dozen or so standards would you like to discuss?

Mike wrote:
Chuck Stickelman wrote:
So what I hear you say is:
Hook the UPS to the physical machine
Have the host OS monitor the UPS's state
When the UPS signals the host it sends a SIGHUP to the Virtual Machines
The VMs should then interpret the SIGHUP as a Shutdown command

Is that what you had in mnd?

Does anyone know if that's how it works?

Chuck
Yes.

The signal may depend on the VM design though. I would hope they have used enough sense to honor some standard.

This really is a near trivial problem. The guests shutdown cleanly during a normal shutdown, yes? Why should a shutdown instituted by UPS software or even admin written (monitoring) scripts be any different?

Mike

To unsubscribe send to ncolug-request@xxxxxxxxxxxxx with 'unsubscribe' in the Subject field.




--
"Perception is strong and sight weak. In strategy it is important to see distant things as if they were close and to take a distanced view of close things." Miyamoto Musashi (1584-1645)


To unsubscribe send to ncolug-request@xxxxxxxxxxxxx with 'unsubscribe' in the 
Subject field.

Other related posts: