Add NUT UPS client installation for new cluster nodes

When freshStart.sh runs on a new PVE node, it now installs nut-client,
configures MODE=netclient, and writes upsmon.conf pointing to monitor-02
as slave — prompts for NUT_PASSWORD during setup.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-22 14:27:45 -04:00
parent 8232ff497d
commit eeea0ebdfa
+71
View File
@@ -466,3 +466,74 @@ fi
if [[ ! -s /etc/hwmonDaemon/.env ]] || grep -q "your_api_key_here" /etc/hwmonDaemon/.env 2>/dev/null; then if [[ ! -s /etc/hwmonDaemon/.env ]] || grep -q "your_api_key_here" /etc/hwmonDaemon/.env 2>/dev/null; then
echo "⚠️ REMINDER: Configure your API key in /etc/hwmonDaemon/.env" echo "⚠️ REMINDER: Configure your API key in /etc/hwmonDaemon/.env"
fi fi
# =============================================================================
# NUT UPS Client — connects to monitor-02 (10.10.10.9) for UPS awareness
# =============================================================================
if [[ "$PLATFORM" == "pve" ]]; then
echo "Installing NUT UPS monitoring client..."
apt-get install -y nut-client
mkdir -p /etc/nut
# Fetch the NUT password from the server
NUT_ENV_URL="http://10.10.10.63:3000/LotusGuild/nut-ups/raw/branch/main/upsmon-client.conf.template"
# Fetch the NUT password from monitor-02 (server holds the canonical password)
# We pull the client conf template and substitute the password inline.
# The password must be set manually or fetched here if you store it securely.
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " NUT UPS Client Configuration"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Enter the NUT password (from /etc/nut/nut.env on monitor-02):"
read -r -s -p " NUT_PASSWORD: " NUT_CLIENT_PASS
echo ""
if [[ -n "$NUT_CLIENT_PASS" ]]; then
# Write nut.conf (client mode)
cat > /etc/nut/nut.conf << 'NUTEOF'
MODE=netclient
NUTEOF
# Fetch upsmon-client.conf.template and substitute password
if curl --max-time 15 --retry 2 -s "$NUT_ENV_URL" -o /tmp/upsmon-client.conf.template; then
sed "s/NUT_PASSWORD_PLACEHOLDER/${NUT_CLIENT_PASS}/g" \
/tmp/upsmon-client.conf.template > /etc/nut/upsmon.conf
rm -f /tmp/upsmon-client.conf.template
else
# Fallback: write inline
cat > /etc/nut/upsmon.conf << UPSMONEOF
MONITOR apcups@10.10.10.9 1 upsmon_remote ${NUT_CLIENT_PASS} slave
MINSUPPLIES 1
SHUTDOWNCMD "/sbin/poweroff"
POLLFREQ 5
POLLFREQALERT 2
RBWARNTIME 43200
NOCOMMWARNTIME 300
FINALDELAY 5
NOTIFYFLAG ONLINE SYSLOG+WALL
NOTIFYFLAG ONBATT SYSLOG+WALL
NOTIFYFLAG LOWBATT SYSLOG+WALL
NOTIFYFLAG FSD SYSLOG+WALL
NOTIFYFLAG SHUTDOWN SYSLOG+WALL
NOTIFYFLAG NOCOMM SYSLOG+WALL
UPSMONEOF
fi
chown root:nut /etc/nut/upsmon.conf 2>/dev/null || true
chmod 640 /etc/nut/upsmon.conf
systemctl enable nut-monitor
if systemctl start nut-monitor 2>/dev/null; then
echo "✓ NUT client connected to UPS monitor on monitor-02"
else
echo "⚠️ NUT client installed but could not connect yet (monitor-02 may not be running NUT server)"
echo " It will connect automatically once nut-server is running on monitor-02."
fi
else
echo "⚠️ NUT password not provided — skipping NUT client setup."
echo " Run manually: apt install nut-client && configure /etc/nut/upsmon.conf"
fi
fi