When deploying VMware ESXi servers in remote offices with APC UPS backup, we need a reliable way to trigger graceful shutdowns during power outages. The standard APC PowerChute Network Shutdown solution requires additional infrastructure (network cards and management servers), which isn't always practical for smaller deployments with Back-UPS Pro models that only have USB connectivity.
ESXi has limited built-in UPS support compared to full Linux distributions. The hypervisor doesn't natively recognize USB-connected UPS devices or provide power management daemons like Network UPS Tools (NUT). This leaves us needing a custom solution.
Here are two approaches that have worked for ESXi 5.1 and later versions:
Option 1: ESXi Custom Script with USB Passthrough
This method requires passing the USB controller to a Linux VM that can monitor the UPS:
# Add to VMX configuration:
usb.present = "TRUE"
usb.generic.allowHID = "TRUE"
usb.quirks.device0 = "0xabcd:0x1234 allow" # Replace with UPS vendor/product IDs
Then install NUT in the Linux VM with configuration:
# /etc/nut/ups.conf
[apcups]
driver = usbhid-ups
port = auto
vendorid = 051D
Option 2: ESXi SSH Script with USB Monitoring
For a more lightweight approach using just ESXi:
#!/bin/sh
# /vmfs/volumes/datastore1/scripts/ups-monitor.sh
while true; do
if ! lsusb | grep -q "APC"; then
/sbin/shutdown.sh && exit
fi
sleep 30
done
Add to crontab with:
* * * * * /vmfs/volumes/datastore1/scripts/ups-monitor.sh >/dev/null 2>&1
1. Test shutdown procedures thoroughly before deployment
2. Consider battery runtime when setting monitoring intervals
3. For ESXi 6.7+, check if native PowerCLI cmdlets can help
4. Always document the solution for local IT staff
If you're using vCenter, you can create a VM alarm that triggers on UPS events:
$alarmMgr = Get-View AlarmManager
$alarm = New-Object VMware.Vim.AlarmSpec
$alarm.Name = "UPS Power Failure"
$alarm.Description = "Triggers when UPS battery is low"
$alarm.Enabled = $TRUE
# Add trigger conditions and actions here
$alarmMgr.CreateAlarm("Folder-group-d1", $alarm)
When deploying ESXi 5.1 servers in remote offices with APC Back-UPS Pro units, the standard network-based shutdown solutions (like PowerChute Network Shutdown) become impractical. The USB connection presents both an opportunity and a technical hurdle since ESXi doesn't natively support USB UPS monitoring.
The solution involves a two-layer approach:
- USB-to-NUT (Network UPS Tools) translation layer
- ESXi-side monitoring script
Prerequisites:
- APC UPS with USB (e.g., Back-UPS Pro 1500)
- ESXi 5.1 host with SSH access
- Temporary Linux machine (can be live CD)
Even without a dedicated server, you can use a minimal Linux setup:
# On Ubuntu/Debian:
sudo apt-get install nut nut-client nut-server
sudo usermod -a -G nut $USER
# Configure /etc/nut/ups.conf:
[apcups]
driver = usbhid-ups
port = auto
Save this as /usr/bin/ups-monitor.sh on ESXi:
#!/bin/sh
NUT_SERVER="linux-gateway-ip"
UPS_NAME="apcups"
POLL_INTERVAL=60
while true; do
STATUS=$(nc $NUT_SERVER 3493 <<< "LIST STATUS $UPS_NAME" | grep -q "OB" && echo "OnBattery")
if [ "$STATUS" = "OnBattery" ]; then
BATTERY_LEVEL=$(nc $NUT_SERVER 3493 <<< "LIST VAR $UPS_NAME" | grep battery.charge | awk -F'"' '{print $2}')
if [ "$BATTERY_LEVEL" -lt 20 ]; then
# Initiate shutdown sequence
localcli system shutdown poweroff -d 60 -r "UPS triggered shutdown"
exit 0
fi
fi
sleep $POLL_INTERVAL
done
Add this to /etc/rc.local before 'exit 0':
/usr/bin/ups-monitor.sh &
For environments where a Linux gateway isn't feasible:
# Identify USB device:
lsusb | grep "American Power Conversion"
# Add to /etc/vmware/esx.conf:
/usb/0/device = "0000:00:1a.0"
/usb/0/vendor = "0x051d"
/usb/0/product = "0x0002"
- Verify USB visibility with:
lsusb -v | grep -i apc
- Check NUT server connectivity:
nc -zv gateway-ip 3493
- Monitor script execution:
ps | grep ups-monitor
Adjust the shutdown thresholds based on your:
UPS Model | Recommended Threshold |
---|---|
Back-UPS Pro 1000 | 25% |
Back-UPS Pro 1500 | 20% |
Smart-UPS 2200 | 15% |