Package: nut-client
Version: 2.8.0-7
Severity: important
File: /sbin/upsmon
X-Debbugs-Cc: fab_bw-deb...@yahoo.com

Dear Maintainer,


   * What led up to the situation?

        During a power cut long enough to bring my UPS batteries to a
        critical level, I noticed that my server was not shut down by
        NUT as I expected.

   * What exactly did you do (or not do) that was effective (or
     ineffective)?

        An UPS is connected to the server and managed by NUT.
        (daemon /sbin/upsmon = nut-monitor)
        NUT is configured to switch off the server in "low battery"
        state.
        The UPS regularly performs a battery self-test, which is
        recognized by UPSMON as a calibration.
        A few days later, there was a power cut.

   * What was the outcome of this action?

        During a power cut long enough to bring the battery level to a
        critical threshold, UPSMON didn't initiate the shutdown
        procedure because it thought the UPS was still in calibration,
        which was wrong, and the server was finally abruptly power down when
        the battery was drained.

   * What outcome did you expect instead?

        When the battery charge level reached a threshold defined as "low
        battery", UPSMON should have initiated the server shutdown procedure.


This bug is known on the github of networkupstools here :
        https://github.com/networkupstools/nut/issues/2168
Bug fix here :
        
https://github.com/networkupstools/nut/pull/2169/commits/b606d757660b85ba9123757609e6ac70a1684cbf


Further Informations :

UPSMON detects a battery self-test as a calibration and records this
state with a flag.

However, it will never clear this flag.

During a power failure, when the battery charge level reaches "low
battery" state, the is_ups_critical function is called.

This detects the "on battery" and "low battery" states, but since the
"calibration" flag is not cleared, the function will block the rest of
the expected procedure. A log entry is created:
is_ups_critical: seems that UPS [Onduleur] is OB+LB now, but it is also
calibrating - not declaring a critical state

This behavior is easy to reproduce :

First test : (Shows that NUT is correctly configured)
- After starting the nut-monitor daemon, simulate a power failure
- The station is powered by the UPS battery
- Battery charge level becomes low
- UPSMON detects this and correctly shuts down the server

Second test : (Show the bug)
- After starting the nut-monitor daemon, simulate or wait for a battery
  self-test
- Wait for the test to be successful, so the station is powered by the
  mains
- Simulate a power failure
- The station is powered by the UPS battery
- Battery charge level becomes low
- UPSMON detects this but thinks the UPS is in calibration. A log
  entry is created, but the station will not be shut down

Third test : (Get around the problem)
- After starting the nut-monitor daemon, simulate or wait for a
  battery self-test.
- Wait for the test to be successful, so the station is powered
  by the mains.
- Restart the nut-monitor daemon (only this one)
- Simulate a power failure
- The station is powered by the UPS battery
- Battery charge level becomes low
- UPSMON detects this and correctly switches off the station


To solve the problem quickly:

Using the NUT v2.8.0 sources provided by Debian Bookworm
(apt source nut),
edit the file ./nut-2.8.0/clients/upsmon.c

Add this just after line 1678:
  if (!strstr(status, "CAL"))
        clearflag(&ups->status, ST_CAL);

see
https://github.com/networkupstools/nut/pull/2169/commits/b606d757660b85ba9123757609e6ac70a1684cbf

Thank you very much
Fabien



-- System Information:
Debian Release: 12.1
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 6.1.0-12-amd64 (SMP w/4 CPU threads; PREEMPT)
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8), LANGUAGE not set
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled

Versions of packages nut-client depends on:
ii  adduser                    3.134
ii  init-system-helpers        1.65.2
ii  libc6                      2.36-9+deb12u3
ii  libupsclient6              2.8.0-7
ii  sysvinit-utils [lsb-base]  3.06-4

Versions of packages nut-client recommends:
ii  bash-completion  1:2.11-6

Versions of packages nut-client suggests:
pn  nut-monitor  <none>

-- Configuration Files:
/etc/nut/nut.conf changed [not included]
/etc/nut/upsmon.conf changed [not included]

-- no debconf information

Reply via email to