8 Replies Latest reply on May 20, 2014 6:22 AM by Tlawry

    emergency shutdown

    StefanoChiappini Enthusiast

       

      Hi,

       

       

      sometimes I need to perform a fast shutdown of my servers, including ESX. Is there a way to tell all the VMs (either linux, windows  or solaris) to shutdown properly, before shutting down ESX servers ? Obviously without logging on each console manually... an automatic procedure would be very appreciated.

       

       

      Thank you in advanca for any hint,

       

       

      Stefano

       

       

        • 1. Re: emergency shutdown
          depping Champion
          VMware EmployeesUser Moderators

          you could script this, with vmware-cmd -l you will get a list of all the running vm's, and you can use this as input for vmware-cmd <config> stop:

          for instance:

           

          VMLIST=`vmware-cmd -l`

          for config in $ do vmware-cmd $ stop

          done

          shutdown -h now

           

           

           

           

           

           

          -


          And if you want to you can also have it entering maintenance mode before shutting down, just to be sure: vimsh -n -e /hostsvc/maintenance_mode_enter

           

           

          Duncan

          My virtualisation blog:

          http://www.yellow-bricks.com

          1 person found this helpful
          • 2. Re: emergency shutdown
            bradley4681 Expert

            The only problem i've found is that initiating a guest shutdown, whether with a script of manually through VC, that windows doesn't always shutdown at all. I've found that having the script run something like pstools or powershell and running the shutdown command on the windows guests remotely and then at the end of the script shutting down the ESX box.

             

             

             

             

            Cheers,

            Bradley Sessions

             

            If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".

            • 3. Re: emergency shutdown
              lamw Guru
              VMware EmployeesCommunity Warriors

               

              I would add the additional to your script:

               

              #assume worse case the VM might have spaces in the name, this will protect against that

              IFS=$'\n'

               

              VMLIST=`vmware-cmd -l`

              for config in $ do #vmware-cmd $ stop

              #this will try to shutdown the VM properly before initiating a hard shutdown

              vmware-cmd "$" trysoft

              done

              vimsh -n -e /hostsvc/maintenance_mode_enter

              shutdown -h now

               

               

              I had to use the field seperator due to some VMs having spaces/special chracters that threw the traditional "vmware-cmd -l" off, also having the "trysoft" flag is better than just passing in stop which I believe defaults to the "hard" flag, unless you really need to bring them down and don't care about the state of the VM. I would probably also suggest doing a sleep for 3-5seconds in between the shutdown, I think if you shutdown dozen or so, it might error out with some warnings. I've seen that happen when I try to mass suspend 10-12 VMs at a time.

               

               

              • 4. Re: emergency shutdown
                esiebert7625 Guru
                vExpert

                 

                Here's another thread on this subject...

                 

                 

                 

                 

                 

                http://communities.vmware.com/message/667815

                 

                 

                 

                 

                Eric Siebert

                VMware Communities User Moderator

                -=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-

                Check out my website: VMware-land

                Read my virtualization blog: SSV Blog

                -=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-

                 

                 

                • 5. Re: emergency shutdown
                  williamarrata Expert

                   

                  I love the scripting, I'm gonna have to try those, thanks for posting the script, anyway, for those who might not be so script happy, the other way to do it is to, from your VC, click the configuration tab, click on the Virtual Machine Startup/Shutdown link, click on the properties, link in the upper right hand corner, here you'll get another window, check the box "Allow virtual machine to Start and stop automatically with the system",

                   

                   

                  Here is where you configure your environment.start with your startup order, choose your servers to start up first, like DC's or databases, then the rest.  Make sure you put them all in Automatic Startup.  Then edit your Default startup Delay and Default Shutdown Delay.  I 've set mine to 20 seconds for startup and 10 seconds for shutdown.  Click OK and your done.

                   

                   

                   

                   

                  Hope that helped.

                   

                   

                  1 person found this helpful
                  • 6. Re: emergency shutdown
                    StefanoChiappini Enthusiast

                     

                    Thank you all for the answers.

                     

                     

                    Just a last question: if I want to suspend the VMs instead of shut them down, how will change the script (and the GUI based procedure) ?

                     

                     

                    Bye, Stefano

                     

                     

                     

                     

                     

                    • 7. Re: emergency shutdown
                      esiebert7625 Guru
                      vExpert

                       

                      Use vmware-cmd suspend instead. Suspending a VM creates a VMSS file for each VM equal in size to the amount of RAM a VM has, the VSWP file is deleted though when a VM is suspended. Be careful using auto-startups, there has been a bug in several versions of ESX 3.x including 3.5 if you use auto startups and restart the hostd service (mgmt-vmware) all your VM's will power down. It has been resolved in several patches.

                       

                       

                       

                       

                       

                      http://kb.vmware.com/kb/1003312

                       

                       

                       

                       

                      Eric Siebert

                      VMware Communities User Moderator

                      -=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-

                      Check out my website: VMware-land

                      Read my virtualization blog: SSV Blog

                      -=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-

                       

                       

                      • 8. Re: emergency shutdown
                        Tlawry Lurker

                        For anyone trying this now the command has been changed since 4.1 from

                         

                        vmware-cmd -l

                         

                        to

                         

                        vim-cmd vmsvc/getallvms

                         

                        Message was edited by: Tlawry

                         

                        here is the script reissue for use on 5.0 and up

                         

                        VMLIST=’vim-cmd vmsvc/getallvms’

                        for config in ${VMLIST}

                        do

                        vim-cmd vmsvc/power.shutdown $config stop trysoft

                        done

                        vim-cmd -hostsvc/maintenance_mode_enter

                        shutdown -h now