View Only
  • 1.  Shutting down via UPS

    Posted Nov 18, 2011 11:39 PM

    Hi everyone

    I've been experimenting with shutting down my VMs and ESXi remotely.

    After some googling and experimenting, I have the following script:



    vim-cmd vmsvc/getallvms  | cut -d' ' -f1 | tail -n +2 | xargs -r -n1 vim-cmd vmsvc/power.suspend
    sleep 180

    /sbin/ && /sbin/poweroff


    I've tested this and it seems to be working.

    One question I do have is is it safe to use `/sbin/ && /sbin/poweroff`. I'm not sure if the scripts are executed in parallel or not. I've tried this on a test host (the script was executed from a machine NOT on the host itself) and it appears to work, but I don't know if I want to risk trying it without getting some feedback. It could be something simple like another sleep command between shutdown and poweroff, but I don't know if this is necessary.

    Also, can the script be executed from a virtual machine on the host it's shutting down? (via plink.exe or something similar)

    Next week I'll be trying to run it from a virtual machine residing on a host to see if it works, and if it does, I'll slowly start to deploy it.



  • 2.  RE: Shutting down via UPS

    Posted Nov 19, 2011 05:47 AM

    The && construct requires that the previous command complete successfully before the next one is run, so they are not parallel.

  • 3.  RE: Shutting down via UPS

    Posted Nov 21, 2011 04:17 PM

    I knew of the '&&' construct from linux. I initially had the shutdown and poweroff separate from each other.

    I will install a new Windows test virtual machine today and see if I can use plink to successfully power down the host.

  • 4.  RE: Shutting down via UPS

    Posted Nov 22, 2011 08:16 PM

    The above script does work.

    However, I also discovered that you can get the virtual machines to suspend when the host powers off. I was aware that you could get them to power on with the host, it just never occured to me that a power down was possible as well.

    That said, is there any reason to not let ESXi suspend hosts when it powers down? I've tested it on a test host with a couple of test VMs and it appears to be working. All I had to do was execute `/sbin/ && /sbin/poweroff` from my VM with APC Powerchute, and the VMs suspended themselves and powered themselves up automatically at the next start.

    The only downside I can think of is forgetting to set a new VM up to auto start/stop - that could cause an issue. Are there any other reasons? Right now if the first command fails to suspend it will try it again during the shutdown script.

  • 5.  RE: Shutting down via UPS

    Posted Nov 21, 2011 03:32 PM

    Hi some UPS manufacture like APC providing same software , please check with your UPS manufacture

    please award points if you see fit.Thanks