4 Replies Latest reply on Dec 11, 2012 5:22 PM by sixdim

    Graceful shutdown of ESXi 5.1 from the shell

    sixdim Lurker

      Just figured out a way to shutdown ESXi 5.1 from the ESXi shell - and it seemed to work on the free edition as well as the paid version of ESXi.

       

      It uses the vim-cmd and the new esxcli commands together to accomplish the goal.  Need to write a full script for this now!!

       

      Here's the link to the full blog post.

        • 1. Re: Graceful shutdown of ESXi 5.1 from the shell
          CTSTech Enthusiast

          Any way of doing it with the free version, without going into maintenance mode?

           

          We used to be able to do this with 5.0

          • 2. Re: Graceful shutdown of ESXi 5.1 from the shell
            sixdim Lurker

            You've probably seen http://kb.vmware.com/kb/1013193 but if not, check it out as a reference.

             

            For a graceful shutdown of an ESXi host (free or not free doesn't matter), you pretty much have to be in maintenance mode.  The *host* won't let you do a shutdown command without it.  A cheat is to put the system into maintenance mode, and pull it out of maintenance mode as the last command in a script - it usually works and exits maintenance mode before it shuts down (just use a delay of 0 for exiting maintenance mode).

             

            So the process that executes (in a script for example) is shutdown guest vms -> enter maintenance mode -> execute host shutdown -> exit maintenance mode (no delay) -> ESXi host shuts down.  When it reboots, it's not in maintenance mode if the last command succeeded (in my testing, it always has).

             

            The other way around this is, if you have all your guest VMs cleanly shutdown, and you don't care about a graceful shutdown of the ESXi host itself (read: at your own risk), you can just use the "halt" command - that still works.  It just immediately halts the ESXi host, and you don't have to be in maintenance mode.

             

            Process would be shutdown guest vms -> halt -> ESXi host powers off/halts.

             

            Hope that helps.  Any other ideas?

            • 3. Re: Graceful shutdown of ESXi 5.1 from the shell
              CTSTech Enthusiast

              sixdim wrote:

              For a graceful shutdown of an ESXi host (free or not free doesn't matter), you pretty much have to be in maintenance mode.  The *host* won't let you do a shutdown command without it. 

               

              With 5.0 I was able to shutdown the ESXi Server using this method, which did not require maintenance mode:

               

              @START "" "C:\Program Files (x86)\VMware\VMware vSphere  CLI\bin\vicfg-hostops.pl" --username=root --password=*********  --server=192.168.39.20 --operation shutdown --force

               

              As long as VMware tools were installed on the VMs and they wer set to automatically startup - ESXi would shut them down first, then itself.

              • 4. Re: Graceful shutdown of ESXi 5.1 from the shell
                sixdim Lurker

                Sadly, this does not work on ESXi 5.1 free edition any longer - it looks like they removed the vCLI access completely for that edition.  PowerCLI is also no longer working with free.  If you try to run any of these commands you'll get an error telling you it's not supported.  I believe the method you listed above should still be fine on an ESXi 5.1 paid version, however.

                 

                The method I have listed above is the only one I know of at the moment that works on 5.1 (free).

                 

                See this blog post -> http://blogs.vmware.com/vsphere/tag/vicfg