This is an old revision of the document!
Tested with XCP-ng 8.2 and a CyberPower CPS1500AVR UPS.
Connect the included USB or serial cable to UPS.
wget https://dl4jz3rbrsfum.cloudfront.net/software/ppb470-linux-x86_x64.sh chmod +x ppb470-linux-x86_x64.sh ./ppb470-linux-x86_x64.sh
pwrstat -status pwrstat -config
Verify startup:
chkconfig --list |grep pwr
For SME Server only which uses runlevel 7:
ln -s /etc/rc.d/init.d/pwrstatd /etc/rc7.d/S93pwrstatd
We don't want the server to shut down immediately upon power failure…we want to wait until the battery gets low before we actually run the shutdown command.
Edit the PowerPanel configuration file:
vi /etc/pwrstatd.conf
And change:
powerfail-shutdown = no #we want to shut down the UPS when the battery gets low, not when the power fails shutdown-sustain = 200 #set this to a little longer than it takes to shut your server down lowbatt-threshold = 15 #don't run the battery completely dead
Restart the service:
/etc/init.d/pwrstatd restart
or
service pwrstatd restart
Commands that run upon power-fail and low-battery events are also specified in the /etc/pwrstatd.conf configuration file. By default, it specifies:
/etc/pwrstatd-powerfail.sh
and
/etc/pwrstatd-lowbatt.sh
You may want to change the lowbatt-threshold to 90
so the box shuts down in the shortest time, then change it back when finished testing.
lowbatt-threshold = 90 service pwrstatd restart tail -f /var/log/pwrstatd.log
These settings are probably not ideal, but are a good start. I think the goal would be to confirm that all VMs are shut nown properly before issuing the shutdown command.
Modifications to above for XenServer:
vi /etc/pwrstatd.conf
And change:
powerfail-shutdown = no #we want to shut down the UPS when the battery gets low, not when the power fails shutdown-sustain = 600 #set this to a little longer than it takes to shut down all VMs and your server lowbatt-threshold = 35 #don't run the battery completely dead and give time to shut down lowbatt-duration = 60 #allow the script to run for 60 seconds before the shutdown
vi /etc/pwrstatd-lowbatt.sh
and append:
xe vm-shutdown power-state=running --multiple