So the company I work for had a deployment scenario in place for there remote branches utilizing VMware Server 2 prior to me coming onboard. I was tasked with the redesign of our remote branch virtualization infrastructure. In comes ESXi 5.0 to replace the fading away VMware Server. Initially they were using a software-based RAID which was controlled through a SLES installation. With the requirements of ESXi we all know that software RAID is not an option. We have since decided on utilizing an Adaptec 2405 RAID controller for these remote servers. Now that my test lab can boot into ESXi I can move forward with the remaining requirements.
Clean Shutdown of VMs and Host
In order for us to have the ability to interface with the APC SmartUPS 1000′s that we have at each location for the server we must find a way to install the APC PowerChute Business Edition Agent (PCBEAgent) for use with monitoring and shutting down the host and VMs. In comes the vSphere Management Assistant (vMA).
In order to install the APC PCBEAgent, we needed either a Linux VM or a Windows VM. In the light of trying to architect a solution that minimizes costs and addition of other hardware, we selected a Linux VM or in this case the vMA. The vMA is a SLES4VMware-based appliance and therefore gives us the ability to build or install agents accordingly. Finally, we just grabbed the installer from APC for the RPM which could be installed on the vMA. Installation on the vMA was simple:
# rpm -ivh pbeagent-xxx.i386.rpm
This placed the PBEAgent in /opt/APC/PowerChuteBusinessEdition/Agent. This will also install the startup script in /etc/init.d. Once it is installed you will need to do the initial configuration by running the config.sh script from within the aforementioned directory. This will allow you to setup the administrative username and password to login and control the agent from the webUI that the agent starts. After you have configured it should start the agent, if not, just start the agent manually. The startup script is PBEAgent and can be started via /etc/init.d/PBEAgent start. Once you start the agent you can connect to it via https://<vMA-IP>:6547. Once you are in the webUI you will notice that there is no communication with the APC unit. Here brings us into the next step, configure Serial Passthrough on the vMA appliance.
Serial Passthrough on the vMA Appliance
In order to configure Serial Passthrough you must power down the vMA appliance. Once you have powered down the vMA appliance you can add the Serial Port interface on the VM. You will select the “Use physical port” option and it should show a device similar to this: /dev/char/serial/uart0
Once this is done power your vMA appliance back on and connect to the PBEAgent webUI. Make sure that you have the APC SmartUPS serial cable connected. It is important to note that you MUST use the provided cable as the pinout is special. From here you will need to configure the UPS. You will want to select “Server Shutdown” option on the left side and then select “System Settings”. Here you will be presented with the options for the signaling type (Smart/Simple/Simple with Interface Expander). You will want to select Smart and for the port use /dev/sttyS0. Once you have done this select the “Smart-UPS 1000″ option on the left side to view the status. If everything was done correctly you should see the Device Status as On line and some other information on the status page.
Configure Server Shutdown Script
Now that we have the proper communication with the UPS and the vMA we need to configure the shutdown script to execute accordingly when we either reach a specified threshold for battery power or as soon as the unit senses loss of power. I will not go into the details of how to select or configure each but feel free to sound off in the comments if you need help. All of the scripts or “cmdfiles” (as APC calls them) are located in /opt/APC/PowerChuteBusinessEdition/Agent/cmdfiles. I have created a simple script that utilizes the vCLI SDK. Here is the script:
# VmShutdown.sh - Script to gracefully shutdown VMs and Host
# Shutdown Guest VMs
/usr/lib/vmware-vcli/apps/vm/vmcontrol.pl --username root --password password --operation shutdown --vmname TESTVM01 --url https://<esxiHostNameOrIP>/sdk/webService
sleep 300 # Change this to a value that suits your environment
# Shutdown ESXi Host
/usr/bin/vicfg-hostops --server --username root --password password --operation shutdown --force --url https://<esxiHostNameOrIP>/sdk/webService
The script can be expanded upon to fit your needs but for the sake of simplicity I have only regarded a single VM and the host itself. The script must be chmod’d for execution which can be done via chmod 755 /opt/APC/PowerChuteBusinessEdition/Agent/cmdfiles/VmShutdown.sh.
Configure the cmdfile within the PBEAgent
Login back into your PBEAgent webUI. From here select “Events” on the left side and then select “Actions”. You will be presented with a long list of Event Actions. You will want to make sure that the events you want to execute shutdown on are showing that shutdown is selected for the event.
Next we will configure the Shutdown Settings to utilize this cmdfile. Select “Server Shutdown” on the left side and then “Shutdown Settings”. You are then presented with the Shutdown Sequence Summary. At the bottom you can click on “Configure”. Click Configure and then scroll to the bottom where you can see “Command File”. Check the checkbox and from the dropdown, select the script to execute. I have configured a file execution duration of 2 minutes to allow for the script to execute fully before the vMA gets shutdown by the PBEAgent itself. You can adjust this to your liking depending on the need and amount of VMs on the single host. Once you have configured this, click on “Apply”.
This concludes the configuration of the PBEAgent for use on an ESXi standalone host. This should now allow for a clean shutdown of both your VMs and the ESXi host itself. It you have any questions then please sound off in the comments below! Have fun!