gersilex / apcupsd-docker

apcupsd in a container; can trigger arbitrary commands on the Docker host
https://hub.docker.com/r/gersilex/apcupsd
MIT License
24 stars 12 forks source link

COMMLOST when connecting UPS via USB #11

Closed boideltier closed 2 years ago

boideltier commented 2 years ago

The default apcupsd.conf for this container specifies a UPSTYPE net. A custom config with UPSTYPE usb is needed for an UPS connected via USB according to the USB configuration in APCUPSD's documentation.

But trying to use the apcupsd.conf file

## apcupsd.conf v1.1 ##
UPSCABLE usb
UPSTYPE usb
DEVICE
BATTERYLEVEL 5
MINUTES 10
LOCKFILE /var/lock
UPSCLASS standalone
UPSMODE disable

and mapping it onto the container with

volumes:
      - /tmp/apcupsd-docker:/tmp/apcupsd-docker
      - /file/path/apcupsd.conf:/etc/apcupsd/apcupsd.conf
      - /file/path/doshutdown:/etc/apcupsd/doshutdown

results in a COMMLOST error using apcaccess:

APC      : 001,017,0429
DATE     : 2022-04-26 15:13:41 +0000  
HOSTNAME : 8bfdba79ab48
VERSION  : 3.14.14 (31 May 2016) unknown
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2022-04-26 15:12:30 +0000  
STATUS   : COMMLOST 
MBATTCHG : 5 Percent
MINTIMEL : 10 Minutes
MAXTIME  : 0 Seconds
NUMXFERS : 0
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
STATFLAG : 0x05000100
END APC  : 2022-04-26 15:14:00 +0000 

with the log also not showing NIS server startup succeeded.

Using the apcupsd.conf as

# /etc/apcupsd/apcupsd.conf (in the apcupsd-docker container)

UPSCABLE usb
UPSTYPE usb
DEVICE
BATTERYLEVEL 5
MINUTES 10

at least results in a successful NIS server startup succeeded, followed by a loss of communications:

/sbin/apcupsd: Warning: old configuration file found.

/sbin/apcupsd: Expected: "## apcupsd.conf v1.1 ##"
/sbin/apcupsd: Found:    "# /etc/apcupsd/apcupsd.conf (in the apcupsd-docker container)
"

/sbin/apcupsd: Please check new file format and
/sbin/apcupsd: modify accordingly the first line
/sbin/apcupsd: of config file.

/sbin/apcupsd: Processing config file anyway.
apcupsd[1]: apcupsd 3.14.14 (31 May 2016) unknown startup succeeded
apcupsd[1]: NIS server startup succeeded
apcupsd[1]: Communications with UPS lost.
/etc/apcupsd/commfailure: line 18: mail: not found
: Warning: old configuration file found.

: Expected: "## apcupsd.conf v1.1 ##"
: Found:    "# /etc/apcupsd/apcupsd.conf (in the apcupsd-docker container)
"

: Please check new file format and
: modify accordingly the first line
: of config file.

: Processing config file anyway.
Warning communications lost with UPS 

A working USB option apcupsd.conf file would be highly appreciated.

gersilex commented 2 years ago

Can you somehow ensure that the USB device is properly handed into your container?

boideltier commented 2 years ago

Solution:

The USB device was not properly handed to the container! First of all, it very confusingly showed up as hiddev0 in /dev/usb/. I was able to verify it being the UPS with lsusb:

Bus 002 Device 005: ID 051d:0002 American Power Conversion Uninterruptible Power Supply

I was able to fix it by adding a line to the docker-compose file:

devices:
   - /dev/usb/hiddev0:/dev/usb/hiddev0

After that, it logged apcupsd[1]: NIS server startup succeeded and the apcaccess logged:

APC      : 001,036,0877
DATE     : 2022-04-26 19:59:03 +0000
HOSTNAME : ecf1b1511e48
VERSION  : 3.14.14 (31 May 2016) unknown
UPSNAME  : ecf1b1511e48
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2022-04-26 19:59:02 +0000
MODEL    : Back-UPS BX1200MI
STATUS   : ONLINE
LINEV    : 237.0 Volts
LOADPCT  : 9.0 Percent
BCHARGE  : 100.0 Percent
TIMELEFT : 41.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 10 Minutes
MAXTIME  : 0 Seconds
SENSE    : Low
LOTRANS  : 140.0 Volts
HITRANS  : 300.0 Volts
ALARMDEL : 30 Seconds
BATTV    : 13.5 Volts
LASTXFER : Automatic or explicit self test
NUMXFERS : 0
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
SELFTEST : OK
STATFLAG : 0x05000008
SERIALNO : 9B2103A21903
BATTDATE : 2001-01-01
NOMINV   : 230 Volts
NOMBATTV : 12.0 Volts
NOMPOWER : 650 Watts
FIRMWARE : 294201G -302201G
END APC  : 2022-04-26 20:05:27 +0000

Thanks!

gersilex commented 2 years ago

Very nice. Thank you for your detailed solution! I put you into a new FAQ section of the wiki so your solution will help more people in the future! :)