UPS APC to shutdown VMs?

killmasta93

Member
Aug 13, 2017
509
18
18
25
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
 

wolfgang

Proxmox Staff Member
Staff member
Oct 1, 2014
4,927
329
83
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.
 

guletz

Well-Known Member
Apr 19, 2017
1,014
143
63
Brasov, Romania
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)
 

killmasta93

Member
Aug 13, 2017
509
18
18
25
@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
 

guletz

Well-Known Member
Apr 19, 2017
1,014
143
63
Brasov, Romania
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

guletz

Well-Known Member
Apr 19, 2017
1,014
143
63
Brasov, Romania
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
 
Jun 1, 2019
135
21
18
33
Moscow, Russia
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.
 

n1nj4888

Member
Jan 13, 2019
91
2
8
39
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.
 
Jun 1, 2019
135
21
18
33
Moscow, Russia
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.
 

guletz

Well-Known Member
Apr 19, 2017
1,014
143
63
Brasov, Romania
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.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE 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 your own in 60 seconds.

Buy now!