u/Electrical-Step-884

▲ 1

Hello everyone,

I hope this is the right place to ask.

I want to get some feedback on my current configuration plan with apcupsd for the following setup:

We have two servers: let's call them Server1 and Server2 (both running proxmox, configured as a ha-cluster).
Additionally, we have two Smart APC UPSs (APC Smart UPS 1500 - SMT1500RMI2UC).

  • Both servers have two power supplies, one is connected to UPS1, the other to UPS2
  • Server1 is connected via USB to UPS1
  • Server2 is connected via USB to UPS2.
  • The power supplies of the core switch are connected to UPS1 and UPS2.

The current idea is to use apcupsd so that in case of a power outage, the servers (and the switch) are only shutdown once both UPSs fall below 30% battery power.

For this, I have this configuration in mind:

Configuration of apcupsd, planned that way for both servers:

/etc/apcupsd/apcupsd.conf

UPSCABLE usb
UPSTYPE usb
DEVICE 
UPSCLASS netmaster
UPSMODE share 
ANNOY 0 
ANNOYDELAY 0
KILLDELAY 0 
BATTERYLEVEL 30 
MINUTES 15 
ONBATTERYDELAY 6 
TIMEOUT 0 
NETSERVER on 
NISIP 0.0.0.0 
NISPORT 3551 
POLLTIME 60 
NOLOGON disable
SCRIPTDIR /usr/local/etc/apcupsd 
PWRFAILDIR /var/run

/etc/apcupsd/hosts.conf on Server1:

MONITOR {IP server2} "server2"
MONITOR {IP core switch} "core switch"

/etc/apcupsd/hosts.conf on Server2:

MONITOR {IP server1} "server1"
MONITOR {IP core switch} "core switch"

On both servers: /etc/default/apcupsd

ISCONFIGURED=yes

also on both servers, so that the batteries will not be drained after the servers have been shutdown - /etc/apcupsd/killpower:

#!/bin/sh
mount -n -o ro /usr 
mount -n -o ro /var 
mount | awk '/ext4/ { print $3 }' | while read line; do
mount -n -o ro,remount $line
done
exit 0

Lastly, the configuration change of /etc/apcupsd/apccontrol to run a custom script on doshutdown instead, also for both servers:

case "$1" in
    onbattery)
        echo "detected power outage, waiting for shutdown command ..."
        ;;
    doshutdown)
        echo "shutdown command received from apcupsd. Checking the other UPS..."
        /etc/apcupsd/graceful_shutdown.sh #shutdown only if the other UPS is low too
        ;;
    offbattery)
        echo "power restored."
        ;;
esac

With the script /etc/apcupsd/graceful_shutdown.sh, for both servers respectively, but only included here once, as they are essentially the same, each querying the IP of their counterpart:

#!/bin/bash

other_server=“otherServerIP”
port=”3551”
other_usv_battery_charge=$(apcaccess -u -h ${other_server}:${port} -p BCHARGE 2>/dev/null | tr -d ' %')

if ((other_usv_battery_charge < 30));
then
    echo "Both UPS at 30% battery power, initiating shutdown" | wall
    # proxmox shutdown commands
    running_vms=$(qm list | awk '/running/ {print $1}')
    running_containers=$(pct list | awk '/running/ {print $1}')
    
    for vmid in $running_vms; do
    echo "shutting down VM $vmid ..."
    qm shutdown $vmid --skiplock
    sleep 5
done

for cid in $running_containers; do
    echo "shutting down container $cid ..."
    pct shutdown $cid --skiplock
    sleep 5
done
sleep 180

/sbin/shutdown -h now

else
exit 99
fi

I would truly appreciate some feedback on this. I haven't yet had the courage to test the configuration as I really don't want to cause any issues with the servers. Maybe I could test it with two vms, one on each host?

It would be great if someone who has a similar setup/more experience with apcupsd could give me their insights and maybe point out some potential errors I made or other things I missed.

Best regards!

reddit.com
u/Electrical-Step-884 — 9 days ago