4 Replies Latest reply on Nov 22, 2011 12:15 PM by danf201110141

    Shutting down via UPS

    danf201110141 Novice

      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/shutdown.sh && /sbin/poweroff



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


      One question I do have is is it safe to use `/sbin/shutdown.sh && /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.






        • 1. Re: Shutting down via UPS
          mcowger Champion

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

          • 2. Re: Shutting down via UPS
            msatya Hot Shot

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


            please award points if you see fit.Thanks


            • 3. Re: Shutting down via UPS
              danf201110141 Novice

              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
                danf201110141 Novice

                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/shutdown.sh && /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.