UPS APC to shutdown VMs?

Discussion in 'Proxmox VE: Installation and configuration' started by killmasta93, May 28, 2019.

  1. killmasta93

    killmasta93 Member

    Joined:
    Aug 13, 2017
    Messages:
    431
    Likes Received:
    16
    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
     
  2. wolfgang

    wolfgang Proxmox Staff Member
    Staff Member

    Joined:
    Oct 1, 2014
    Messages:
    4,763
    Likes Received:
    315
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. guletz

    guletz Active Member

    Joined:
    Apr 19, 2017
    Messages:
    888
    Likes Received:
    121
    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)
     
  4. killmasta93

    killmasta93 Member

    Joined:
    Aug 13, 2017
    Messages:
    431
    Likes Received:
    16
    @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
     
  5. wolfgang

    wolfgang Proxmox Staff Member
    Staff Member

    Joined:
    Oct 1, 2014
    Messages:
    4,763
    Likes Received:
    315
    Yes it will.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    killmasta93 likes this.
  6. guletz

    guletz Active Member

    Joined:
    Apr 19, 2017
    Messages:
    888
    Likes Received:
    121
    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.
     
    #6 guletz, Jun 6, 2019
    Last edited: Jun 6, 2019
    killmasta93 likes this.
  7. Vladimir Bulgaru

    Joined:
    Jun 1, 2019
    Messages:
    96
    Likes Received:
    10
    It is definitely possible. Planning to get this working with my Smart UPS and will report back on the results.
     
  8. guletz

    guletz Active Member

    Joined:
    Apr 19, 2017
    Messages:
    888
    Likes Received:
    121
    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
     
  9. Vladimir Bulgaru

    Joined:
    Jun 1, 2019
    Messages:
    96
    Likes Received:
    10
    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.
     
  10. n1nj4888

    n1nj4888 Member

    Joined:
    Jan 13, 2019
    Messages:
    67
    Likes Received:
    2
    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.
     
  11. Vladimir Bulgaru

    Joined:
    Jun 1, 2019
    Messages:
    96
    Likes Received:
    10
    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.
     
  12. killmasta93

    killmasta93 Member

    Joined:
    Aug 13, 2017
    Messages:
    431
    Likes Received:
    16
    only if the APC have network if not by usb has to be configured on the host
     
  13. guletz

    guletz Active Member

    Joined:
    Apr 19, 2017
    Messages:
    888
    Likes Received:
    121
    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.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice