Monday, June 22, 2015

APC UPS monitoring on Proxmox with automatic shutdown

an APC UPS is connected to the Proxmox VE server locally by USB or COM.
In case of a power failure Proxmox VE will not shutdown when the battery is getting to low.
Simple because there is nothing installed on the server to tell that Proxmox VE should make a clean shutdown for the VM's and then shutdown the server properly.

With apcupsd this can be done.
It is also reachable by browser so you can see the remaining battery and more.

Nearly every APC UPS should work with apcupsd.

Tested with:

Proxmox 3.4
APC SC420                         ( serial interface connected to COM1 on the server )
APC SC450                         ( serial interface connected to COM1 on the server )
MGE Evolution 1550           ( serial interface connected to USB on the server )


Prep your VM's so Proxmox can shut them down cleanly.

You can find out how to do this in the Proxmox First Server installation guide. - Open the Proxmox "Shell"

Update your package repositories.
type:   apt-get update

Now it's time to install the webserver to be used to check the status of the battery and so on in the browser.
type:   apt-get install apache2

Time to install apcupsd and neccesary packages
type:   apt-get install apcupsd apcupsd-doc apcupsd-cgi

One installed configure some settings in the config file.
In the config file everything is well explained. 
type:   nano /etc/apcupsd/apcupsd.conf

Following are the settings i modified or should be checked. You should change according to your situation.

UPSTYPE apcsmart
DEVICE /dev/ttyS0                       (this is COM1 on my server)

BATTERYLEVEL 25            (when batterylevel hits 25% your proxmox server will shutdown)
MINUTES 10                                  (or when 10 minutes battery time is remaining) 


Press "CTRL+X" to exit.
Press "Y" to save.

Now activate the just edited configuration file
type:   nano /etc/default/apcupsd

Change the "ISCONFIGURED" to yes

Press "CTRL+X" to exit.
Press "Y" to save.

Start the APCUPS deamon
type:   /etc/init.d/apcupsd start

Now open your browser and go to the following link:

With apcaccess status you can check the UPS on the commandline

Nothing to explain anymore, you should know by now if it works ;)

Different config files for UPS Models:

APC SC402 / SC450 (Serial Connection)
UPSTYPE apcsmart
DEVICE /dev/ttyS0                       (this is COM1 on my server)

MGE Evolution 1550 (USB Connection


Dave Klassen said...
This comment has been removed by the author.
Dave Klassen said...

I have been testing apcupsd a lot lately it seems on a few platforms. Prior to proxmox I used primarily redhat releases, and in RedHat/Centos releases apcupsd comes preconfigured to HALT the system, not simply power it off. This actually helped with a few things:

1. Leaving it in the halted state runs the UPS power down faster.
2. The machine physically turns off when there is no more power.
3. The systems remembers being in the last known state of "powered on", before failure.
4. So... when power is reapplied it starts automatically with no human intervention.

I am not going to say there are not other complications to this problem. For instance different BIOS releases may have different capabilities. In my most recent BIOS, it has an option to remember state, stay off, or turn on... when when power is reapplied. I think the best setting for a very simple proxmox installation is 'Power On'.

If you don't test all of these issues you can't expect your system to turn on automatically after a power failure event, even if the system does shutdown 'gracefully'. So this brings me back to the default Proxmox installation of Debian. In Debian releases the 'doshutdown' sequence in the script used to power the machine down: /etc/apcupsd/accontrol, does not provide the -H flag to /sbin/shutdown. The -H flag is the option used to HALT the system without removing power (ie. powering off the device). Without the -H option your machine powers off completely, and your UPS might not actually run out of power by the time the power comes back on. It is likely desirable that you add the -H option to this line(111):

${SHUTDOWN} -h -H now "apcupsd UPS ${2} initiated shutdown"

When you do this, and set your BIOS APC setting to automatically power on when power is applied, you can better guarantee your server will power backup after a power loss event. If you have your server in a remote location, with limited expenses/resources involved like I do, you will be able to better appreciate your UPS, by actually running through a test and confirming you have it setup in the required fashion.

V.Kamphuis said...

Hi Dave,

Thanks for your feedback.
I will have a look at your message and test this.

As soon as i tested it i will put it in the post.

Again thanks!

Unknown said...

Ahh, so you recommend installing APCUPSd directly on the host?

On my ESXi server (I am currently planning to migrate to Proxmox) I run APCUPSd on a dedicated small Ubuntu guest, which on shutdown SSH:es in to the host to shut it down.

Are there any comparative benefits or drawbacks to running APCUPSd in a VM or Container instead of directly on the host?

Much obliged,

V.Kamphuis said...

Yes, it's running directly on the host.

Benefit is that you don't have to run a extra vm for your APCUPSd.
But when you configure the vm the right way so i won't be shutdown before the other vm's i don't see any drawback to that either.

Basicly it's what you would prefer ;)

Unknown said...

And what about starting when power comes back?

V.Kamphuis said...

In the BIOS of your Server you can set what the server shoudl do when the power comes back.

avs said...

I have Proxmox 6.0-4 and tried this as shown above, but I am not sure if it is working properly. The webpage does not load.
This is my output in Shell:

root@proxmox:~# apcaccess status
APC : 001,017,0422
DATE : 2019-12-03 10:16:04 -0500
HOSTNAME : proxmox
VERSION : 3.14.14 (31 May 2016) debian
UPSMODE : Stand Alone
STARTTIME: 2019-12-02 16:42:30 -0500
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME : 0 Seconds
TONBATT : 0 Seconds
CUMONBATT: 0 Seconds
STATFLAG : 0x05000100
END APC : 2019-12-03 11:23:50 -0500

Does this status above look correct? I find it strange that the Status is "COMMLOST" and the MBATTCHG is 5 Percent.

Any advice on how to get the webpage running?