VMware vSphere

 View Only
  • 1.  ESXI Hosts Shutdown with APC UPS How To

    Posted Aug 29, 2024 04:10 PM

    This is a detailed how to as I have been seeing alot of wrong info online or outdated info. This is done for 2 esxi 8.0.3 hosts using Powerchute Business Edition on one and Powerchute Serial Network Edition on the other. Both are done with Windows Server 2022 Vms. Vcenter is irrelevant here because esxi hosts will be shutdown directly.

    1-Very important to configure ESXI Host to have autostart enabled. Host, Manage, Autostart settings, 

    Needs to be enabled "yes" and stop action should be "shutdown"

    This will allow all vms to shut down cleanly. Important to go to each vm and choose autostart configure, should either be "shut down" or "system default" which is what we chose above.

    2- Now we need to enable ssh on esxi hosts. Host, manage, services, TSM SSH, choose auto start "start and stop with host", and then start service. Make sure it's running. You will have a yellow warning about ssh, just acknowledge and dismiss the notification.

    3- Now, we need to setup ssh access from the vm to the esxi host. On your Windows Server vm, open terminal and generate and install the keys to establish passwordless ssh between vm and esxi host. Run the following in terminal

     ssh-keygen -t rsa

    Follow the instructions, just press enter for default location, enter twice for no password phrase. When done you will have a pic with ssh key.

    Now to install to esxi host, substitute 192.168.1.96 with esxi host ip address. We want to use the root account so everything else stays the same. It will ask for the password, enter the root password for the esxi host, that's about it


    cat ~/.ssh/id_rsa.pub | ssh root@192.168.1.96 'cat >>/etc/ssh/keys-root/authorized_keys'

    Now lets confirm passwordless ssh, Close the terminal and open new terminal window, type the following substituting you esxi host ip

    ssh root@192.168.1.96

    If its working you will see root in your terminal



  • 2.  RE: ESXI Hosts Shutdown with APC UPS How To

    Posted Aug 29, 2024 04:29 PM

    Continued

    4- Now we need to install the apc software in the vm. If you choose Powerchute Business edition - it's x86 and will be installed in Program files (x86),

    Serial shutdown is 64 bit and will get installed to Program files. Make sure your apc ups is findable in device manager, usb connected ups will show up as battery, serial connected will not but make sure you have serial port enabled and it shows up in device manager. This will vary depending on your setup. With Vcenter, you can choose the running vm and add hardware - serial port or host usb device. Make sure the vm is connecting to the ups automatically through reboots. In esxi it's probably different but same idea.

    5- Install powerchute, save your username and password for browser login. Make sure after install when you open browser and start initial setup that your ups is visible and communicating. Go to shutdown settings, that's where you will need to add you shutdown cmd files. That's next lol.

    6- Create 2 text files. The 1st is "remote_shutdown.cmd"   enter the following into it with notepad and save

    @echo off
    rem
    rem   Maximize for best viewing
    rem   This command file provides examples of proper command file syntax
    rem
    rem   Command Files run by PowerChute Business Edition must be placed in this directory.
    rem
    rem   Use the full path name of executable programs and external command files.
    rem
    rem   The @START command must be used to run executable programs (see example below).
    rem   For the @START command, path names that include spaces must be enclosed in quotes; 
    rem   arguments for the executable must be outside the quotes.  A double quote must
    rem   precede the quoted path name.  For example, to execute a command file in 
    rem   c:\Program Files\APC\PowerChute Business Edition\agent\cmdfiles called myShut.exe,
    rem   the following line should be entered in the command file:
    rem
    @START "" "C:\Program Files (x86)\APC\PowerChute Business Edition\agent\cmdfiles\shutdownESXI.bat"
    rem
    @echo on

    Now, we need to create the actual shutdown file, shutdownESXI.bat, create the text file and insert the following substituting your esxi host ip address

    ssh root@192.168.1.96 "/sbin/shutdown.sh && /sbin/poweroff"

    Save it and copy both files to C:\Program Files (x86)\APC\Powerchute Business Edition\agent\cmdfiles

    or the same cmdfiles folder for Powerchute Serial Network which will be in Program Files

    Now open each file and fix permissions. I just chose everyone but you may wish to choose a different account. Right click and choose properties, security and add "everyone", full control. Do both files.




  • 3.  RE: ESXI Hosts Shutdown with APC UPS How To

    Posted Aug 29, 2024 04:35 PM

    Continued 

    7-  Now we need to fix permissions with the service. Go to windows services and choose the apc agent. It has different names in different editions but choose a different user. Logon on a server os with "administrator" and enter Windows Server Administrator acct password. Also tick interact with desktop. Restart the service. 

    8- Now log back into powerchute from web browser and when you get to choosing a file for shutdown, choose "remote_shutdown.cmd" and save. Save settings and now you can test this. 1st open a browser window for the esxi host so you can see what's going on. Click Test in the Powerchute browser, if all is correct, esxi host will begin shutting down vms.

    Hope this helps someone!!!!!




  • 4.  RE: ESXI Hosts Shutdown with APC UPS How To

    Posted Aug 30, 2024 09:41 AM

    It might be worth pointing out that this is for single-host, single UPS setups. Powerchute BE does not support shutting down via vCenter.

    This should not be tried with clustered hosts as this disables the standalone host autostart features, and hence a clean guest shutdown cannot be assured. Unless you are happy to accept the risks of doing VM power-off or kill for UPS commanded shutdowns.

    For clustered setups you would need Powerchute Network Shutdown, which no doubt is setup in a very different way.




  • 5.  RE: ESXI Hosts Shutdown with APC UPS How To

    Posted Aug 30, 2024 11:56 AM

    Update::

      Just a couple of notes, as far as using this.

    1- Definitely recommend Powerchute Serial Shutdown. This is the successor to the previous personal and business editions. It is working flawlessly on about 10 computers, both for local shutdowns and network shutdowns.

    2- When setting permissions for the two files created for folder cmdfiles, you can just make sure administrator is checked and allowed to execute, "Everyone" isn't absolutely necessary. Works fine with just administrator acct.

    As for Stephens comments above, he is absolutely right, if you are controlling with vcenter- this program doesn't work and is not reccomended if you are using Vmotion or Vsan. In that case you WILL need PCNS virtual machine AND you will need to pay for a license. That will work for Vcenter. BUT, if you have simple ESXI hosts and are NOT using any extended features, this will work. Remember, the correct way to control your ESXI hosts once attached to Vcenter is through Vcenter.