UPS APC to shutdown VMs?

killmasta93

Renowned Member
Aug 13, 2017
973
58
68
31
Hi,
I was wondering if someone else has accomplished with apcupsd to shutdown the vms after certain amount of battery. Or should i go with NUT? Currently got it working great with apcupsd but wanted to know if its possible to shutdown the vms?

Thank you
 
Hi,

if the server will be powered off through apcupsd all guest will get a shutdown notification.
What the guest will do depend on the guest os and the setting.

But if the guest does not shut down in shutdown time the guest will be killed.
 
Hi,

If I remember apc daemon has the status command where it show the amount of battery that is remaining. Using this info you can create a script who can do anything you want, including shutdown any vm. Also I think you can install apc daemon on any VM/CT using some statment like network(you need to provide the IP of the apc server who is comunicate with the apc battery) if I remember (I do not have a PC now), and the apc daemon will act as a agent, but you can specify different settings compare witth the apc server(like if battery is less then x % then shut down the vm)
 
@wolfgang so in theory if i configured correctly should turn off the VMs if they have the guest agent?

@guletz thats correct but currently have by USB using APC 1300
 
thats correct but currently have by USB using APC 1300

Hi,

My answer was exactly for this case. One one hw node you have apc daemon with usb link to the apc ups(let say master). Then you can configure the apc daemon to listen on network.
On any other host (hw or vm at least) you will install the same apc daemon but you will configure to connect on master apc daemon using network and you can also give different parameters for shutdown, and so on.

But you will face a nasty problem when your non-master apc VM will go down, before the master hw. Then until muster will reach the x % battery level (< non-master VM) the power will be restore. But at this point you must have "something" that will be able to start your all VM that was shutdown. Maybe a custom script in the master apc daemon config (who has by default scripts for events like power down / up)

Good luck.
 
Last edited:
  • Like
Reactions: killmasta93
Hi,

Basicaly on master hw node, you need this(apcupsd.conf):
.....
NETSERVER on
# the IP address of the hw node
NISIP 192.168.x.y
NISPORT 3551

On any VM/CT you will need this:
....
UPSCABLE ether
UPSTYPE net
DEVICE 192.168.x.y:3551
 
So, here's the gist of the process.

Intro
The network configuration is the following:
  • there is the SmartUPS connected to network via the Management Card
  • there is the server(-s) connected to network via the NICs
UPS setup
The UPS needs an IP to connect correctly to the network. By default (after reset) it uses DHCP to grab an available address, but it's best to give it a static IP on the network. Another setting is the login passphrase under the Shutdown configuration options and you may need to change that one.

Proxmox setup
In order for the UPS to be able to shut the server down, there needs to be a client installed on the OS. The one that APC provides is called the PowerChute. Download it and follow installation instructions (very straightforward). After the install it will be available on the port 6547 (don't know if it differs) and you need to access it to finalise the configuration. It will ask you about the network topology, login settings to the Management Card and that passphrase you've setup earlier. If all goes well, the communication is established.

I will test later if the default settings are sufficient for the normal shutdown routine. In any case, there is an option to indicate custom commands to run during the shutdown routine. Within the UPS you can configure the shutdown conditions.
 
  • Like
Reactions: bellocarico and kal
Not a production environment, but in my home lab I use NUT. Synology NAS is connected via USB to an APC BackUPS and acts as the UPS “server”. Proxmox nodes are connected power-wise to the same UPS and have NUT installed on them in netclient mode listening for power issue/commands from the synology over the LAN.

All seems to work well and, although I haven’t tested recently, I recall the synology UPS Server notified the Proxmox NUT clients after X minutes of being on battery (can’t recall whether you can configure a UPS battery % remaining trigger?) and they shutdown the VMs and then themselves gracefully (followed by the UPS itself). on power restore to the UPS, all restarted successfully - Although I recall I had to change the Proxmox host (Intel NUC) bios settings to get them to automatically start up on power restore from the UPS.
 
  • Like
Reactions: M-a-x-G
Some additional notes on the APC and PowerChute client.
You may want to set up the timings accordingly and here's the flowchart for power on and power off that i found useful:
  • off (UPS goes on battery -> notifies the PowerChute -> PowerChute triggers the shutdown of the server and UPS -> server is shut down -> UPS is shut down):
    • set the shutdown event within PowerChute to UPS On Battery. It tells when the PowerChute attempts to shutdown the server. You will want to give it a decent delay, i.e. the reasonable time long enough so that any power issues that last a couple of seconds/minute don't disrupt the servers, but short enough so that the battery doesn't die before the server is powered off.
    • important! when shutting down the server, you want to shut down the UPS as well. The reason is - you will need an event to trigger the server's and equipment's power on event. You will need "Turn off the UPS" option inside the PowerChute.
    • set the shutdown configuration on the UPS. Two options here: Shutdown Delay - 0 (the default timeout is enough to shutdown Proxmox) and "time on battery lasts longer than 9999" (this is for the shutdown to occur regardless of the battery level and so on).
  • on (UPS goes to AC -> sends power to the server and equipment -> equipment starts on Power On):
    • for the server - go to BIOS and activate start on AC power on (depending on the server the option can be named differently)
    • for other equipment - most of NAS and networking equipment have the start on power on function.
Successfully tested the setup on my ProxMox server with the UPS Network Management Card 2.
 
  • Like
Reactions: kal
only if the APC have network if not by usb has to be configured on the host

No. Like I said before, you can have a server with usb connection to a APC battery. The if this server have network, then any other server (hw or virtual with network access ) can use the APC info (power on/off, battery level) to shutdown.
 
Hi,
did anyone set up a Proxmox 6.0 controlled shutdown with PowerChute Network Shutdown v4.3 (APC SmartUPS 3000 RM with a Network Management Card) via LAN?
I saw Debian 10 is not in the compatibility chart (https://download.schneider-electric...AYQNP_R87_EN.pdf&p_Doc_Ref=SPD_SJHN-7AYQNP_EN).
Is it also necessary to install openjdk-11-jre or it would be sufficient to install openjdk-11-jre-headless (much less stuff..)?
Thanks in advance

edit: in the official guide (https://download.schneider-electric.com/files?p_Doc_Ref=SPD_PMAR-9HBK44_EN) "PowerChute includes a private Java Runtime Environment (JRE) that is bundled with the software". But is it working?
 
Last edited:
As reported here installing NUT and install package in general might break your Proxmox (and any specialist Linux such OMV, Zentyal,...) and/or an upgrade of this Linux might break the configuration of the package.

So based on this reflection, I propose you to install NUT or APC software inside a LXC or VM and passing the USB or Serial to this dedicated CT/VM than when this CT/VM pass in battery mode simply send a shutdown command via SSH to your Proxmox.

If you, like a lot of us use pfSense, OPNsense or OpenMediaVault these OS already include NUT and will let's you to manage easily this situation.

Always remember the KISS principle (Keep It Stupid Simple) aka one task by Machine/VM/CT/OS than everything will run smoothly.
 
Hello,
Just spend Hours trying tho make apcupsd run in a LXC.
I've an APC USB UPS connected on the host
I've passed the usb to the LXC this way in the LXC conf:

Code:
lxc.cgroup.devices.allow: c 189:* rwm
lxc.mount.entry: /dev/bus/usb/001 dev/bus/usb/001 none bind,optional,create=dir

and run this on the Host:
chmod o+rw /dev/bus/usb/001
and/or
chmod o+rw /dev/bus/usb/001/010

This is the result of udevadm info /dev/bus/usb/001/010 in the host

Code:
udevadm info /dev/bus/usb/001/010
P: /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.6
N: bus/usb/001/010
L: 0
E: DEVPATH=/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.6
E: DEVNAME=/dev/bus/usb/001/010
E: DEVTYPE=usb_device
E: DRIVER=usb
E: PRODUCT=51d/2/106
E: TYPE=0/0/0
E: BUSNUM=001
E: DEVNUM=010
E: MAJOR=189
E: MINOR=9
E: SUBSYSTEM=usb
E: USEC_INITIALIZED=40697041102
E: ID_VENDOR=American_Power_Conversion
E: ID_VENDOR_ENC=American\x20Power\x20Conversion
E: ID_VENDOR_ID=051d
E: ID_MODEL=Back-UPS_XS_1400U_FW:926.T2_.I_USB_FW:T2
E: ID_MODEL_ENC=Back-UPS\x20XS\x201400U\x20\x20FW:926.T2\x20.I\x20USB\x20FW:T2\x20
E: ID_MODEL_ID=0002
E: ID_REVISION=0106
E: ID_SERIAL=American_Power_Conversion_Back-UPS_XS_1400U_FW:926.T2_.I_USB_FW:T2_4B1925P01987
E: ID_SERIAL_SHORT=4B1925P01987
E: ID_BUS=usb
E: ID_USB_INTERFACES=:030000:
E: ID_VENDOR_FROM_DATABASE=American Power Conversion
E: ID_MODEL_FROM_DATABASE=Uninterruptible Power Supply

This is the result of udevadm info /dev/bus/usb/001/010 in the LXC:

Code:
udevadm info /dev/bus/usb/001/010
P: /devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.6
N: bus/usb/001/010
L: 0
E: DEVPATH=/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.6
E: DEVNAME=/dev/bus/usb/001/010
E: DEVTYPE=usb_device
E: DRIVER=usb
E: PRODUCT=51d/2/106
E: TYPE=0/0/0
E: BUSNUM=001
E: DEVNUM=010
E: MAJOR=189
E: MINOR=9
E: SUBSYSTEM=usb

So the passtrough is not "complete"
I've tried everyting I found but that's the best I have and apctest cannot connect to the UPS

Code:
apctest

2020-07-12 00:14:34 apctest 3.14.14 (31 May 2016) debian
Checking configuration ...
sharenet.type = Network & ShareUPS Disabled
cable.type = USB Cable
mode.type = USB UPS Driver
Setting up the port ...
apctest FATAL ERROR in apctest.c at line 321
Unable to open UPS device.
  If apcupsd or apctest is already running,
  please stop it and run this program again.
apctest error termination completed

Any suggestion to have full passtrough of an UPS to an LXC ?

It would be much appreciated :)
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!