Skip to content

Conversation

@danielfdickinson
Copy link
Contributor

Maintainer: me
Run tested: ath79, CR5000, current master for openwrt and openwrt-packages
In addition to while developing testing each part did a final:

  1. Did sysupgrade -n
  2. Edited nut_driver, nut_server, nut_monitor, and nut_cgi with appropriate configs via LuCi app (not yet pushed)
  3. Verifed all daemons started
  4. Queried UPS (upsc upsname@localhost)
  5. Set a variable via nut-cgi
  6. Executed a a forced shutdown (FSD) (and it came back up properly too)

Description:
The fixes #6843 by properly 'procdifying' the initscripts as well fixing a number of minor nits and adding USB hotplug support.
It also makes forced UPS shutdown (FSD) via upsmon actually work by adding a script to implement the necessary actions.

We want to include the symlinks to the generated configurations
in conffiles so that if the user replaces them symlinks with
traditional NUT configuration it is preserved across sysupgrade.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
@danielfdickinson
Copy link
Contributor Author

danielfdickinson commented Aug 28, 2018

Correct me if I'm wrong, but it looks like Travis never actually got to trying to compile/package nut and some other package is what borked out?

Is there a way to retrigger Travis (without code change) once whatever is broken is fixed (local build works BTW). @commodo @jow- @thess

@danielfdickinson danielfdickinson mentioned this pull request Aug 28, 2018
@danielfdickinson
Copy link
Contributor Author

Ooops...forgot the migration path (there have been UCI changes)...even if Travis gets working, please don't merge yet.

@danielfdickinson
Copy link
Contributor Author

danielfdickinson commented Aug 28, 2018

Well, broke something ... <mutters incoherently> ... will push when resolved.

Daniel F. Dickinson added 15 commits August 29, 2018 00:12
Clarify the different between the common nut-driver portions of
nut-server and the nut-server (upsd) proper.  nut-driver can't
be used without nut-server so there is no compelling reason
to split into a separate package, but the reorganization makes
such a move easier and makes it clear what each bit is for.

While we continue to use a single initscript, it's a properly
procdified one which handles the upsd daemon as a different
instance than the driver instances.  This resolves a race
condition in which upsd and drivers fail to start do to
a degree of interdepedence.

Also properly 'procd'ifies the nut-server initscript.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
usbhid-ups has the necessary information in the source, so
let's support USB hotplugging out of the box.  Takes advantage of
the procd support now in nut-server initscript.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
This fully procdifies nut-monitor, which fixes some issues with
very slow restarts (due to /lib/functions/procd.sh using a very
long delay for non-native scripts doing restart) as well as gives
respawning, etc.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
Forced shutdown of the UPS was not actually happening before
due to lack of specific commands doing the shutdown.  This
(and the nut-driver initscript) fix that.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
This allows config for setting variables and/or running
commands from the CGI.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
Even though nut-cgi doesn't run a daemon, using procd triggers
is helpful for updating the generated config file when the
UCI config changes.  So implement this and 'modernize' nut-cgi initscript

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
By default use a non-privileged user that is different than
the server or driver (when they are running non-privileged).
This is recommended by upstream.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
Instead of making POWERDOWNFLAG an uci option the user can
only change it via initscript edits.  This avoids chance for users
to miss the required change to nut-driver when setting an UCI option
for nut-monitor which results in failure to do FSD on the UPS.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
We're using --without-wrap unconditionally anyway, so this legacy
dependency needs to be removed.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
Reduce compilation time and complexity by not building documentation
we don't use.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
The source code has multiple licenses so update SPD-X header.

NB: The previously unlisted licenses are not applicable to parts
actually built in any configuration for OpenWrt, but rather to
unused (by us) source code.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
Avoid potential issues with space or other strangeness by
quoting filenames through the initscripts.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
Cosmetic edit.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
Removes a duplicate directory creation and a stray newline.

Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
Signed-off-by: Daniel F. Dickinson <cshored@thecshore.com>
@danielfdickinson
Copy link
Contributor Author

Ok, the breakage was a need to do dirclean since I rebased against latest master for openwrt, packages, and luci.

It's working. And I've tested the patches with them reordered somewhat sensibly (so the first 5 I want to cherry-pick and verify on 18.06 for backporting).

Oh and I eliminated the difference in UCI; no migration is necessary.

@danielfdickinson
Copy link
Contributor Author

Run tested ath79, CR5000, current masters

  1. Clean slate (sysupgrade -n) test. Configs added vi LuCI. Tested FSD
  2. Rebooted, verified monitoring, FSD, CGI. All good.

@commodo
Copy link
Contributor

commodo commented Aug 29, 2018

@cshoredaniel
In the "More Options" top-right there should be a "Trigger Build" button that let's you trigger a build [also by specifying some custom settings if you want].
That is, the button exists if you have some rights in the openwrt github account.
I'm not sure if it shows up for your PR though.

@danielfdickinson
Copy link
Contributor Author

@commodo I don't have rights on the openwrt github account (I removed myself when I was ill and didn't think I'd be back to OpenWrt).

@danielfdickinson
Copy link
Contributor Author

Hmmm...let's see if we can kick off a new build without the Travis access....

@hnyman hnyman merged commit 59acb42 into openwrt:master Aug 30, 2018
@malakingpusa
Copy link

Hi @cshoredaniel, we managed to compile the updated source codes and so far the forced shutdown command works. Thanks for this.

We bumped in into some problems when we tried to use the same UCI files that was setup when we were reproducing the issue. Our next step is to start from a new /etc/config/nut_server and nut_monitor which are generated by the installed packages.

We will update you with the results.

@danielfdickinson
Copy link
Contributor Author

@malakingpusa Hmmm....can you describe problems? If the upsdrvctl thing, you need to stop the nut-driver before using it, as it's not meant to be used with the driver already running (and procd will restart the driver fairly quickly (i.e. before -k has a chance to read all the descriptors and do it's thing).

Can you share a sanitized version of the configs you are using so I can see what's up?

@malakingpusa
Copy link

Here is my /etc/sysupgrade.conf:

root@TPLINKAC1750:~# cat /etc/sysupgrade.conf 
## This file contains files and directories that should
## be preserved during an upgrade.
# /etc/example.conf
# /etc/openvpn/

When I try upsc CP37@localhost:

root@TPLINKAC1750:~# upsc CP37@localhost
Error: Driver not connected

This works as expected:

root@TPLINKAC1750:~# /etc/init.d/nut-server stop
root@TPLINKAC1750:~# upsdrvctl shutdown
Network UPS Tools - UPS driver controller reboot-7986-gdc9388a
Network UPS Tools - Generic HID driver 0.41 (reboot-7986-gdc9388a)
USB communication driver 0.33
Using subdriver: CyberPower HID 0.4
Initiating UPS shutdown

Why is there no /lib/nut/usbhid-ups -a CP37 in my processes?

root@TPLINKAC1750:~# ps | egrep "nut|ups"
 1292 root      1100 S    /usr/sbin/upsmon -D
 1311 nut       1100 S    /usr/sbin/upsmon -D
 2146 nut       1040 S    /usr/sbin/upsd -D -u nut
 2155 root      1200 S    egrep nut|ups

When does the following part of the /etc/init.d/nut-server get executed?

procd_set_param command /lib/nut/${driver} -D -a "$cfg" ${RUNAS:+-u $RUNAS}

Right now, just have to make upsc work and test multiple UPSes.

@danielfdickinson
Copy link
Contributor Author

Two questions: How long after boot are you attempting upsc (it takes some time for the driver to come up because of the way the procd + hotplug work in this case)?
If you want to 'force' the driver to come up quickly, I think the following will work:
/etc/init.d/nut-server stop CP37 && /etc/init.d/nut-server start CP37
I'm puzzled by the 'no such dir' --- does it appear on subsequent flashes or just coming from the previous version?

@malakingpusa
Copy link

How long after boot are you attempting upsc (it takes some time for the driver to come up because of the way the procd + hotplug work in this case)? >> hours because i left it last night and then started again when I reported for work.

I'm puzzled by the 'no such dir' --- does it appear on subsequent flashes or just coming from the previous version? >> never encountered them with previous flashes without the new compiled packages.

will try this command you suggested:

/etc/init.d/nut-server stop CP37 && /etc/init.d/nut-server start CP37

@malakingpusa
Copy link

Did a reboot and after 32 minutes I checked upsc CP37:

root@TPLINKAC1750:~# uptime
 18:29:38 up 32 min,  load average: 0.14, 0.04, 0.01
root@TPLINKAC1750:~# upsc CP37
Error: Driver not connected
root@TPLINKAC1750:~# /etc/init.d/nut-server stop CP37 && /etc/init.d/nut-server start CP37
root@TPLINKAC1750:~# ps | egrep "nut|ups"
 1276 root      1100 S    /usr/sbin/upsmon -D
 1293 nut       1100 S    /usr/sbin/upsmon -D
 1607 nut       1040 S    /usr/sbin/upsd -D -u nut
 2063 root      1200 S    egrep nut|ups
root@TPLINKAC1750:~# upsc CP37
Error: Driver not connected
root@TPLINKAC1750:~# sleep 10
root@TPLINKAC1750:~# upsc CP37
Error: Driver not connected
root@TPLINKAC1750:~# ./killupsd.sh 

Killing upsd process id 1607...

Starting UPS...
Network UPS Tools - UPS driver controller reboot-7986-gdc9388a
Network UPS Tools - Generic HID driver 0.41 (reboot-7986-gdc9388a)
USB communication driver 0.33
Using subdriver: CyberPower HID 0.4

Starting upsd...
Network UPS Tools upsd reboot-7986-gdc9388a
fopen /var/run/nut/upsd.pid: No such file or directory
listening on ::1 port 3493
Connected to UPS [CP37]: usbhid-ups-CP37

Displaying processes...
 1276 root      1100 S    /usr/sbin/upsmon -D
 1293 nut       1100 S    /usr/sbin/upsmon -D
 2075 root      1200 S    /bin/sh ./killupsd.sh
 2080 root      1364 S    /lib/nut/usbhid-ups -a CP37
 2082 root       972 S    /usr/sbin/upsd
 2084 root      1200 S    egrep nut|ups

Displaying UPS stats...
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 20
battery.mfr.date: CPS
battery.runtime: 15450
battery.runtime.low: 300
battery.type: PbAcid
battery.voltage: 24.0
battery.voltage.nominal: 24
device.mfr: CPS
device.model: CP1500EPFCLCD
device.serial: CRNGV2000016
device.type: ups
driver.name: usbhid-ups
driver.parameter.offdelay: 60
driver.parameter.ondelay: 30
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.serial: CRNGV2000016
driver.parameter.synchronous: no
driver.version: reboot-7986-gdc9388a
driver.version.data: CyberPower HID 0.4
driver.version.internal: 0.41
input.transfer.high: 260
input.transfer.low: 170
input.voltage: 227.0
input.voltage.nominal: 230
output.voltage: 260.0
ups.beeper.status: disabled
ups.delay.shutdown: 60
ups.delay.start: 30
ups.load: 0
ups.mfr: CPS
ups.model: CP1500EPFCLCD
ups.productid: 0501
ups.realpower.nominal: 900
ups.serial: CRNGV2000016
ups.status: OL
ups.test.result: No test initiated
ups.timer.shutdown: -60
ups.timer.start: -60
ups.vendorid: 0764

@danielfdickinson
Copy link
Contributor Author

In the 'config driver' section, can you try setting

option vendorid [4-hex-digits-of-usb-vendord-id]
option productid [4-hex-digit-usb-product-id]

e.g for my setup I have

option vendorid 0437
option productid ffff

Perhaps there is some issue with hotplug messing things up without the vendorid and product id on your device (I think I tried both ways, but will try to make some time to test again).

Wait: Please use 'master' not '18.06' The backported changes haven't been merged yet (I guess @hnyman is waiting for results with 'master')

@danielfdickinson
Copy link
Contributor Author

@malakingpusa Please let me know the results with master; I believe you are seeing the old version of the initscripts and no hotplug because 18.06 doesn't have the updates yet.

@malakingpusa
Copy link

@cshoredaniel thanks for pointing that out. Asking our SW engineer now to compile OpenWrt from master. We will test and then update you again. Thanks.

@malakingpusa
Copy link

@cshoredaniel SW engineer is asking if we will compile source code from latest commit or latest release?

@danielfdickinson
Copy link
Contributor Author

Latest commit

@malakingpusa
Copy link

Great. Will tell my SW engineer.

@malakingpusa
Copy link

Bumped into this issue when I tried to install kmod-usb2:

root@TPLINKAC1750:/etc/backup# opkg install kmod-usb2_4.9.124-1_mips_24kc.ipk
Installing kmod-usb2 (4.9.124-1) to root...
Collected errors:
 * satisfy_dependencies_for: Cannot satisfy the following dependencies for kmod-usb2:
 * 	kernel (= 4.9.124-1-0a60c6508dd4dd55f2b1728b63a404f0) * 	kernel (= 4.9.124-1-01d03f01348999520673f4931cedaac3) * 	kernel (= 4.9.124-1-01d03f01348999520673f4931cedaac3) * 	kernel (= 4.9.124-1-01d03f01348999520673f4931cedaac3) * 
 * opkg_install_cmd: Cannot install package kmod-usb2.

kmod-usb2 is needed by lsusb

@danielfdickinson
Copy link
Contributor Author

danielfdickinson commented Sep 7, 2018

@malakingpusa Ah, are you building only the core and then using snapshots? That won't work. You need to either build everything you want and include it in the image, or you need to use snapshots build (which might already have the updated NUT code).

@malakingpusa
Copy link

I see. Building now nut packages with usbutils and kmod-usb2. Thanks @cshoredaniel .

@malakingpusa
Copy link

Hi @cshoredaniel , we managed to compile from the master branch. Here are the results of testing:

  1. Compiled master branch with kmod-usb2 enabled.
  2. Flashed openwrt-ar71xx-generic-archer-c7-v4-squashfs-sysupgrade.bin.
  3. Executed opkg update.
  4. Executed opkg install usbutils.
  5. Updated /etc/config/nut_server:
config driver 'CP37'
	option driver usbhid-ups
	option port auto
        option vendorid 0764
        option productid 0501
        option serial CRNGV2000016 
        option pollinterval 15
        option offdelay 60
        option ignorelb 

config user
	option username nut
	option password passwd
	option upsmon master

config listen_address
	option address ::1
	option port 3493

config upsd 'upsd'
	option maxage 25
	option statepath /var/run/nut
  1. Updated /etc/config/nut_monitor:
config upsmon 'upsmon'
	option runas nut
	option minsupplies 1
#	option shutdowncmd '/usr/sbin/nutshutdown'
        option shutdowncmd "date >> /root/diag/shutdown.msg"
#	option notifycmd /path/to/cmd
#	list defaultnotify SYSLOG
	option pollfreq 5
	option pollfreqalert 5
 	option hostsync 15
	option deadtime 25
#	option onlinemsg "online message"
#	option onbattmsg "on battery message"
#	option lowbattmsg "low battery message"
#	option fsdmsg "forced shutdown message"
#	option comokmsg "communications restored message"
#	option combadmsg "communications bad message"
#	option shutdowmsg "shutdown message"
#	option replbattmsg "replace battery message"
#	option nocommmsg "no communications message"
#	option noparentmsg "no parent message"
#	option onlinenotify "online notify flag 1|0"
#	option onbattnotify "on battery notify flag 1|0"
#	option lowbattnotify "low battery notify flag 1|0"
#	option fsdnotify "forced shutdown notify flag 1|0"
#	option comoknotify "communications restored notify flag 1|0"
#	option combadnotify "communications bad notify flag 1|0"
#	option shutdownotify "shutdown notify flag 1|0"
#	option replbattnotify "replace battery notify flag 1|0"
#	option nocommnotify "no communications notify flag 1|0"
#	option noparentnotify "no parent notify flag 1|0"
#	option rbwarntime 4200 # replace battery warn time
#	option nocommwarntime 300 # no communications warn time
	option finaldelay 5 # final delay
#	option certpath /path/to/ca/dir
#	option certverify 0
#	option forcessl 0

config master
	option upsname CP37
	option hostname localhost
	option port 3493
	option powervalue 1
	option username nut
	option password passwd

#config slave
#	option upsname upsname
#	option hostname localhost
#	option port # optional port number
#	option powervalue 1
#	option username upsuser
#	option password upspassword
  1. Executed reboot.
  2. Executed ps | egrep "nut|ups":
 1218 root      1100 S    /usr/sbin/upsmon -D
 1234 nut       1100 S    /usr/sbin/upsmon -D
 1537 nut       1040 S    /usr/sbin/upsd -D -u nut
 1942 root      1188 S    egrep nut|ups
  1. Tried to query the UPS and this is what I got:
root@TPLINKAC1750:~# upsc CP37
Error: Driver not connected
  1. Tried to force a stop and start on the nut-server and driver is still not connected:
root@TPLINKAC1750:~# /etc/init.d/nut-server stop CP37 && /etc/init.d/nut-server start CP37
root@TPLINKAC1750:~# upsc CP37
Error: Driver not connected
root@TPLINKAC1750:~# ps | egrep "nut|ups"
 1218 root      1100 S    /usr/sbin/upsmon -D
 1234 nut       1100 S    /usr/sbin/upsmon -D
 1537 nut       1040 S    /usr/sbin/upsd -D -u nut
 2020 root      1188 S    egrep nut|ups
  1. Tried to manually start UPS using upsdrvctl with -u nut:
root@TPLINKAC1750:~# /usr/sbin/upsdrvctl -u nut start CP37
Network UPS Tools - UPS driver controller reboot-8011-g6bbb220255
Network UPS Tools - Generic HID driver 0.41 (reboot-8011-g6bbb220255)
USB communication driver 0.33
No matching HID UPS found
Driver failed to start (exit status=1)
  1. Tried removing -u nut from upsdrvctl. UPS query still does not work:
root@TPLINKAC1750:~# /usr/sbin/upsdrvctl start CP37
Network UPS Tools - UPS driver controller reboot-8011-g6bbb220255
Network UPS Tools - Generic HID driver 0.41 (reboot-8011-g6bbb220255)
USB communication driver 0.33
Using subdriver: CyberPower HID 0.4
root@TPLINKAC1750:~# upsc CP37
Error: Driver not connected
  1. Tried to kill upsd and relaunch with -u nut and got permission denied message:
root@TPLINKAC1750:~# kill -9 1537 && /usr/sbin/upsd -u nut
Network UPS Tools upsd reboot-8011-g6bbb220255
fopen /var/run/nut/upsd.pid: No such file or directory
listening on ::1 port 3493
Can't connect to UPS [CP37] (usbhid-ups-CP37): Permission denied
  1. Tried to kill upsd and relaunch without -u nut and upsc CP37 worked:
root@TPLINKAC1750:~# kill -9 2057 && /usr/sbin/upsd
Network UPS Tools upsd reboot-8011-g6bbb220255
kill: No such process
listening on ::1 port 3493
Connected to UPS [CP37]: usbhid-ups-CP37
root@TPLINKAC1750:~# upsc CP37
battery.charge: 100
battery.charge.low: 10
battery.charge.warning: 20
battery.mfr.date: CPS
battery.runtime: 15450
battery.runtime.low: 300
battery.type: PbAcid
battery.voltage: 24.0
battery.voltage.nominal: 24
device.mfr: CPS
device.model: CP1500EPFCLCD
device.serial: CRNGV2000016
device.type: ups
driver.name: usbhid-ups
driver.parameter.offdelay: 60
driver.parameter.ondelay: 30
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.productid: 0501
driver.parameter.serial: CRNGV2000016
driver.parameter.synchronous: no
driver.parameter.vendorid: 0764
driver.version: reboot-8011-g6bbb220255
driver.version.data: CyberPower HID 0.4
driver.version.internal: 0.41
input.transfer.high: 260
input.transfer.low: 170
input.voltage: 229.0
input.voltage.nominal: 230
output.voltage: 261.0
ups.beeper.status: disabled
ups.delay.shutdown: 60
ups.delay.start: 30
ups.load: 0
ups.mfr: CPS
ups.model: CP1500EPFCLCD
ups.productid: 0501
ups.realpower.nominal: 900
ups.serial: CRNGV2000016
ups.status: OL
ups.test.result: No test initiated
ups.timer.shutdown: -60
ups.timer.start: -60
ups.vendorid: 0764
  1. Tried to send killpower to UPS via upsdrvctl shutdown:
root@TPLINKAC1750:~# /usr/sbin/upsdrvctl shutdown
Network UPS Tools - UPS driver controller reboot-8011-g6bbb220255
Network UPS Tools - Generic HID driver 0.41 (reboot-8011-g6bbb220255)
USB communication driver 0.33
Can't claim USB device [0764:0501]: No such file or directory
Driver failed to start (exit status=1)
  1. Tried to kill usbhid-ups and upsd process and then executed upsdrvctl shutdown and it worked:
root@TPLINKAC1750:~# ps | egrep "nut|ups"
 1218 root      1100 S    /usr/sbin/upsmon -D
 1234 nut       1100 S    /usr/sbin/upsmon -D
 2033 root      1364 S    /lib/nut/usbhid-ups -a CP37
 2066 root       976 S    /usr/sbin/upsd
 2091 root      1188 S    egrep nut|ups
root@TPLINKAC1750:~# kill -9 2033 2066 && /usr/sbin/upsdrvctl shutdown
Network UPS Tools - UPS driver controller reboot-8011-g6bbb220255
Network UPS Tools - Generic HID driver 0.41 (reboot-8011-g6bbb220255)
USB communication driver 0.33
Using subdriver: CyberPower HID 0.4
Initiating UPS shutdown

@malakingpusa
Copy link

Other notes:
I added options for pollinterval and ignorelb in the driver config but when i tried to read /etc/nut/ups.conf, this is what I get:

root@TPLINKAC1750:~# cat /etc/nut/ups.conf 
# Config file automatically generated from UCI config
[CP37]
driver = usbhid-ups
port = auto
serial = CRNGV2000016
offdelay = 60
ondelay = 30
pollfreq = 30
vendorid = 0764
productid = 0501

I need the pollinterval so I do not get stale data and the ignorelb so I can override the battery.charge.low parameter.

@danielfdickinson
Copy link
Contributor Author

danielfdickinson commented Sep 11, 2018

@malakingpusa Ah, I missed adding those parameters to the options available driver. By any chance can you submit a PR which adds missing parameters. I got rid of the auto-parameter stuff (i.e. not specifically named) because I had various concerns about it, and because LuCI requires explicitly named parameters and I want the parameters documentation in the NUT package.

@malakingpusa
Copy link

@cshoredaniel submitted #7001 for this. thanks.

@malakingpusa
Copy link

Hi @cshoredaniel ,

Just to clarify, for now while waiting for the updated parameters for the driver, is it correct that I can now use the router by doing the following:

  1. After boot up, kill process for upsd.
  2. Do "upsdrvctl start upsname" (makes /lib/nut/usbhid-ups process) and then run upsd. The "upsc upsname" command will and should work at this point.
  3. If time comes that I need to shutdown the UPS, I simply kill the usbhid-ups and upsd processes and finally send "/lib/nut/usbhid-ups -a* upsname -k".

???

@danielfdickinson
Copy link
Contributor Author

I believe part of your problem is #6966 (which I'm working on right now). As a quick work around remove the leading 0 on any product id (middle number in xxxx/xxxx/* | \ in /etc/hotplug.d/usb/30-libhid-... and also remove [ -d /var/run/nut ] from the same file, and you should need to do the killing of upsd and/or upsdrvctl start.

Also to FSD just upsmon -c shutdown and it should bring down all UPSes.

@malakingpusa
Copy link

Wow! Worked from reboot after doing the workaround you mentioned as I can see output from upsc command. As a result, usbhid-ups is now running as nut user and no longer as root.

I added another UPS and it can now detect and read status from both UPSes after reboot, of course I had to add the new UPS in the /etc/config/nut_server.

This is how the nut processes look now:

root@TPLINKAC1750:~# ps | egrep "nut|ups"
  558 nut       1436 S    /lib/nut/usbhid-ups -D -a CP37 -u nut
 1288 root      1100 S    /usr/sbin/upsmon -D
 1330 nut       1100 S    /usr/sbin/upsmon -D
 1617 nut       1044 S    /usr/sbin/upsd -D -u nut
 2030 root      1188 S    egrep nut|ups

Also was able to run the command /etc/init.d/nut-server stop && upsdrvctl shutdown, it worked and below is the output:

root@TPLINKAC1750:~# /etc/init.d/nut-server stop && upsdrvctl shutdown
Network UPS Tools - UPS driver controller reboot-8011-g6bbb220255
Network UPS Tools - Generic HID driver 0.41 (reboot-8011-g6bbb220255)
USB communication driver 0.33
Using subdriver: CyberPower HID 0.4
Initiating UPS shutdown
Network UPS Tools - Generic HID driver 0.41 (reboot-8011-g6bbb220255)
USB communication driver 0.33
Using subdriver: CyberPower HID 0.4
Initiating UPS shutdown

Thanks for the help @cshoredaniel ! Just need that fix for the parameters so I get a reliable reading from the UPSes and avoid stale outputs.

@danielfdickinson
Copy link
Contributor Author

@malakingpusa I'd recommend upsmon -c shutdown over /etc/init.d/nut-server stop && upsdrvctl shutdown as the former also properly shutsdown the device (e.g. filesystems etc).

But great news!

@malakingpusa
Copy link

@cshoredaniel here are the processes from a fresh reboot before trying upsmon -c shutdown:

root@OpenWrt:~# ps | egrep "nut|ups"
  562 nut       1444 S    /lib/nut/usbhid-ups -D -a CP37 -u nut
 1296 root      1100 S    /usr/sbin/upsmon -D
 1311 nut       1100 S    /usr/sbin/upsmon -D
 1673 nut       1044 S    /usr/sbin/upsd -D -u nut
 1938 root      1188 S    egrep nut|ups

Then tried executing upsmon -c shutdown and here is what I got:

root@OpenWrt:~# upsmon -c shutdown
Network UPS Tools upsmon reboot-8011-g6bbb220255
Monitors UPS servers and may initiate shutdown if necessary.

usage: upsmon [OPTIONS]

  -c <cmd>	send command to running process
		commands:
		 - fsd: shutdown all master UPSes (use with caution)
		 - reload: reread configuration
		 - stop: stop monitoring and exit
  -D		raise debugging level
  -h		display this help
  -K		checks POWERDOWNFLAG, sets exit code to 0 if set
  -p		always run privileged (disable privileged parent)
  -u <user>	run child as user <user> (ignored when using -p)
  -4		IPv4 only
  -6		IPv6 only

And then I tried upsmon -c fsd, command went through but UPS did not shutdown.

root@OpenWrt:~# upsmon -c fsd
Network UPS Tools upsmon reboot-8011-g6bbb220255

Here are the remaining processes after upsmon -c fsd:

root@OpenWrt:~# ps | egrep "nut|ups"
  562 nut       1444 S    /lib/nut/usbhid-ups -D -a CP37 -u nut
 1668 nut       1044 S    /usr/sbin/upsd -D -u nut
 1966 root      1188 S    egrep nut|ups

@danielfdickinson
Copy link
Contributor Author

@malakingpusa Is this with multiple UPSes or a single one? (working on a build now for the other changes so will test again). It was working for me, but maybe I broke something?

@danielfdickinson
Copy link
Contributor Author

@malakingpusa UPS takes about 20-30 seconds after last slave exits before UPS is shutdown and (it should) come back in about 10 seconds if UPS is still powered on. Does that make a difference?

@ivanich
Copy link

ivanich commented Sep 19, 2018

Using blazer_usb nut driver and found that this PR brings https://github.com/openwrt/packages/pull/6897/files#diff-b43121d3cb6f04f9a4f58f93c7970813R150 option which is not available in blazer_usb thus it cannot start with the following error
Wed Sep 19 08:56:12 2018 daemon.info blazer_usb[3871]: Network UPS Tools - Megatec/Q1 protocol USB driver 0.12 (reboot-8069-ge8cbfedc72)
Wed Sep 19 08:56:12 2018 daemon.info blazer_usb[3871]:
Wed Sep 19 08:56:12 2018 daemon.info blazer_usb[3871]: Fatal error: 'pollfreq' is not a valid variable name for this driver.
Wed Sep 19 08:56:12 2018 daemon.info blazer_usb[3871]:

The second issue is permissions to /dev/bus/usb/001/00*
I can get it working with 2 steps:

  • commenting out pollfreq from /etc/init.d/nut-server
  • adding rw perms to /dev/bus/usb/001/00*

I'm using latest master compiled from sources

@malakingpusa
Copy link

malakingpusa commented Sep 28, 2018

@malakingpusa UPS takes about 20-30 seconds after last slave exits before UPS is shutdown and (it should) come back in about 10 seconds if UPS is still powered on. Does that make a difference?

hi @cshoredaniel , managed to explore this again after some serious load at the office.

while waiting for the parameters fix, did just what was described here:
If you wish to use a 'standard' NUT config just remove the symlinks in /etc/nut and replace them with regular NUT configuration files.

I still can query and send shutdown to UPS after that which is really an improvement.

Next step I am starting now on is to soak test the UPS to check if I won't get stale data errors over the weekend.

So far log looks good:

root@OpenWrt:~# tail -f /var/log/ups60.log 
2018-09-28 08:23:54 UPS: CP37 [OL] Battery Charge: 100% Runtime: 14880 seconds Load: 0 PID=1964
2018-09-28 08:24:54 UPS: CP37 [OL] Battery Charge: 100% Runtime: 14880 seconds Load: 0 PID=1964
2018-09-28 08:25:54 UPS: CP37 [OB DISCHRG] Battery Charge: 100% Runtime: 15420 seconds Load: 0 PID=1964
2018-09-28 08:26:54 UPS: CP37 [OB DISCHRG] Battery Charge: 100% Runtime: 14563 seconds Load: 0 PID=1964
2018-09-28 08:27:54 UPS: CP37 [OB DISCHRG] Battery Charge: 100% Runtime: 14563 seconds Load: 0 PID=1964
2018-09-28 08:28:54 UPS: CP37 [OL] Battery Charge: 100% Runtime: 14605 seconds Load: 0 PID=1964
2018-09-28 08:29:54 UPS: CP37 [OL] Battery Charge: 100% Runtime: 14202 seconds Load: 0 PID=1964
2018-09-28 08:30:54 UPS: CP37 [OL] Battery Charge: 100% Runtime: 14202 seconds Load: 0 PID=1964
2018-09-28 08:31:54 UPS: CP37 [OL] Battery Charge: 100% Runtime: 14116 seconds Load: 0 PID=1964

@danielfdickinson
Copy link
Contributor Author

In case folks haven't seen it elsewhere: FYI I've posted PR: #7638 which ought to do must of what's now in master except the USB hotplug bits (as that's a new feature IMO). If you can, please test and comment!

@danielfdickinson danielfdickinson deleted the pr-nut-fixes branch January 1, 2019 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nut package

5 participants