0

I have a remote Pi4 running Buster and Network UPS Tools 2.7.4.

Most of the time it works fine, but after a long power outage and NUT shutdown, the Pi cannot connect to the UPS.

pi@raspmountain:~/webcam $ upsc apc500
Error: Connection failure: Connection refused

If I reboot, it connects fine:

pi@raspmountain:~/webcam $ upsc apc500
Init SSL without certificate database
battery.charge: 100
battery.charge.low: 10
<snip>

I don't know why this is or how to fix it. I have searched extensively and while I have found answers to similar questions, none about this specific problem.

I have tried restarting the nut-driver.service, but that doesn't work.

Note that this is a standalone NUT installation. The Server and client services are not needed. There is no networking involved. The NUT driver service never starts because the UPS doesn't show up on the USB bus after a cold boot. It takes a warm boot to get the UPS to connect. I need to figure out how to get the UPS to connect without having to boot the Pi.

Buadhai
  • 115
  • 7
  • Have you checked to see if it's got a systemd unit? Have you searched the Internet with the symptoms you've described? If not - why? If so - why isn't it mentioned in your question? – Seamus Apr 23 '22 at 08:59
  • I have edited my question to show that I have searched the Internet and found similar questions but nothing like this. I did mention in my original question that I had tried restarting the nut-driver.service. On the Pi the NUT services are located in /lib/systemd/system. But, you'd already know that had you done sufficient research to be truly helpful. – Buadhai Apr 23 '22 at 12:28
  • Buadhai: Please know that it is not my job (or anyone's here) to do "sufficient research" to answer your question. Unless I didn't get that memo, you are entitled to nothing here beyond simple courtesy. It is your job to do the research - REFERENCE. As a consolation, here's a free opinion: An overly-developed sense of entitlement is not the best way to get help. – Seamus Apr 23 '22 at 21:38
  • I apologize for the snide remark. I was reacting to my perception that you seemed more interested in being critical than helpful. – Buadhai Apr 24 '22 at 01:46
  • Are you sure you don't need the nut-server service? I'm pretty sure that nut-monitor needs it and upsc won't work without it. Possibly you need to restart both nut-server.service and nut-driver.service (driver first). The driver systemd file probably should have systemd-udev-settle.service in both After= and Wants= so it doesn't start too soon. If that doesn't help, it might be useful to either add an autorestart with a delay or add a prereq that loops until the UPS shows up on USB. – user10489 Apr 24 '22 at 23:40
  • rereading your additions. So after a cold boot, lsusb doesn't list the ups? Try restarting udevd and try lsusb again? – user10489 Apr 24 '22 at 23:44
  • @user10489 - You're right NUT monitor needs NUT server which needs NUT driver. – Buadhai Apr 25 '22 at 00:26
  • @user10489 I marked your answer as being accepted even though I can't test this on the subject Pi. It is in a remote location, so I can't shut it down and remove and restore power. I'll have to wait until there is a power outage. I think though that the Update paragraph in your answer is exactly what needs to be done. Incidentally, I tried this on a Pi here at home, but it connects to the UPS even after a cold boot. Same exact model Pi (Pi 4 Model B Rev 1.2). But, different models of APC UPS: Back-UPS CS 500 (remote) vs Back-UPS BX750MI (local). – Buadhai Apr 25 '22 at 01:36
  • I'm wondering if there is an issue delaying detection of the UPS, like possibly a bad USB cable or something. – user10489 Apr 25 '22 at 04:02
  • It's entirely possible. The cable came with the UPS which I bought early this year. Next time I visit this location I'll take a spare cable with me. In the past I have had trouble with Pi4s not recognizing or dropping USB cameras. The webcam scripts that I have actually check to see if the camera has been detected before capturing an image. Oddly, that almost never happens any more, even though it's the same Pies and the same cameras. A mystery. – Buadhai Apr 25 '22 at 10:27
  • On second thought, if the cable were bad then why does the UPS connect immediately upon a command line reboot and why does it always stay connected until the next power outage? – Buadhai Apr 25 '22 at 10:41

1 Answers1

1

Connection refused indicates that there is nothing listening on the network port. Most likely the nut daemon has died. Rebooting fixes this by restarting the daemons.

You could fix this without rebooting by manually restarting the daemons, possibly with systemctl restart nut-server nut-monitor or similar.

For a more permanent fix, you need to check your logs and determine why the daemon is dying and either correct that or adjust the systemd config for the daemon to restart it on failure.

Update:

Since you indicate in your comments that the UPS doesn't show up on the usb bus after cold start, it might be helpful to put your usb rescan commands into a script. Add some tests to make sure it does not reset the USB if the UPS is there, and maybe some delays too, and then add that script as a ExecStartPre= for the nut-driver.service.

user10489
  • 981
  • 1
  • 5
  • 10
  • I have edited the OP to note that this is a standalone installation of NUT so that the server and monitor services are not needed. The driver service never starts because no UPS is detected on the USB bus after a cold boot. It takes a warm reboot to get the UPS to show up. I hadn't figured all this out at the time of the OP. – Buadhai Apr 24 '22 at 21:55
  • @Buadhai: Are you sure there's a difference between warm & cold boots on a RPi? I've always assumed there's not, but...?? – Seamus Apr 25 '22 at 00:42
  • @Seamus - What I was calling a "cold boot" was when the Pi had been without power for a while and then boots when power is restored. In this case NUT has shut down the Pi with this /sbin/shutdown -h +0 before the power goes down. What I'm calling a warm boot is when you reboot the Pi from the command line and the Pi is never without power. – Buadhai Apr 25 '22 at 01:25
  • @Buadhai: Yes - that's true, but all processing is stopped. And if all processing is stopped, then it all must be re-started again. This is why I asked initially about systemd - I guessed that there was a unit file that controlled its startup - have you looked for that? Also - unless you physically remove power (pull the plug), your RPi is never without power - shutdown & poweroff are essentially the same as halt in RPi OS. You'll find +5V present, and except for "low power mode", you'll find 3V3 as well. – Seamus Apr 25 '22 at 05:27
  • @Buadhai: I'm surprised your research hasn't led you to the nut GitHub site. There's a lot of activity, and a lot of contributors - ordinarily a good sign - but there are also 451 open issues going back to 2013. Don't know what that means, but you'll only learn if you try. My experience with nut was very poor initially (~8 yrs ago) - I've not tried it since. Finally, there are 27 nut-related Q&A here on RPi SE - maybe look at those? Again, this is mostly about *research*. – Seamus Apr 25 '22 at 05:46
  • @Seamus - The Pi is totally without power when the UPS battery dies. When power is restored, the Pi does what I call a cold boot. After that kind of cold boot the Pi does not connect to the UPS. At that point a reboot results in the Pi connecting to the UPS. The USB cable is brand new and came with the APC UPS which I bought about four months ago. – Buadhai Apr 25 '22 at 08:26