Libnetwork-ups-tools, can someone help?

(Kevin Moses) #1

I installed this but I’m not sure what it did. I’m familiar with the package from the arch repos, but this doesn’t seem like it installed anything.
I looked at the history of when it was built less than 2 months ago.
It doesn’t appear like this has been completely built or something.
What I’m trying to do is download a UPS driver for my cyberpower battery backup.
What do void users normally use for this.

(Kevin Moses) #2

Oh, I think the libnetwork-ups-tools is the run-time library and I need to install network-ups-tools.

(Kevin Moses) #3

Well I’ve tried for two hours to get this to work. I installed Network-UPS-tools, and I keep getting Can’t chdir to /run/ups: no such file or directory.

I already had installed libnetwork-ups-tools, and so I tried to remove that to see if that might be a problem, but apparently it is required for network-ups-tools as a dependency.

I also tried to add a symbolic link from /etc/ups and /usr/share/ups to /run, but when I do that it says that there is a permission issue and that nut is the owner of the driver and 0770 or something.

I get writepid: fopen /run/ups/ permission denied.
Fatal error: unable to create listener socket.

Bind /run/ups/usbhid-ups-myups failed permission denied.

Current user: nut (uid 998)
He wants me to set up a different owner in run/UPS.

But to me I shouldn’t have to be doing all this. I’m not sure what’s going on.
The hid driver is the driver I should be using. And I have my port set to auto.
I have set this up before and Arch Linux and it worked just fine.
Any ideas what I can do?

(Masato the Empty) #4

I have a cyberpower…
I don’t recall having to created /run/ups… You certainly don’t want any symlinks to another existing directory.

You need to:

  • configure ups (set up /etc/ups/ups.conf)
  • turn on upsdrvctl service - you can’t use upsd without first enabling this. It creates the communications socket(s) that upsd will use.
  • turn on upsd (default config works I think, but you can tweak - /etc/ups/upsd.conf)
  • turn on upsmon (tweak via /etc/ups/upsmon.conf)

I don’t remember off hand all of the options I had to mess with (it’s been set-and-forget for me) but I do know I had to set ups.conf. If I had any trouble (it wouldn’t have been a whole lot) then it was in setting up ups.conf… But I did fine using information from upstream’s website.

EDIT: additional note - the startup script for upsdrvctl sets up the run directory, which the daemon then populates)

(Kevin Moses) #5

Yeah, I setup ups.conf
driver = upbhid-ups
port = auto
desc = “Cyberpower ga425”

Then I ran upsdrvctl start myups.
Here’s the output:

Network UPS tools - UPS driver controller 2.7.4
Network UPS tools - generic hid driver 0.41 (2.7.4)
USB communication driver 0.33
Can’t chdir to /run/ups: no such file or directory
Driver failed to start (exit status=1)

(Kevin Moses) #6

Also, the output of nut-scanner:
driver = “usbhid-ups”
port = “auto”
vendorid = "0764’
productid = “0501”
product = “Cp425hga”
vendor = “CPS”
bus = “001”

Also, lsusb:
Bus 001 Device 094: ID 0764:0501 cyberpower systems, Inc CP1500 AVR UPS

(Masato the Empty) #7

The runit service creates the /run/ups directory. Look at it (the service file) for the correct ownership/permissions. If you’re not running upsdrvctl via the runit service, then you have to create it manually. (see /etc/sv/upsdrvctl/run to see how it would be run as a runit service - I really recommending enabling the runit service anyway…)

(Kevin Moses) #8

Okay so I’m very new to runit as a whole. But based on your advice, this is what I did:
I created a symbolic link to /etc/sv/upsdrvctl in /var/service/

When I did that it listed:
Network UPS tools - UPS driver controller 2.7.4
Network UPS tools - generic hid driver 0.41 (2.7.4)
USB communication driver 0.33

It did not go back to a bash prompt, and it did not give me an error.

So I Ctrl + c out of it and ran this command:
Sv up upsdrvctl
No error.
Then I ran sudo upsdrvctl start, and this is what I got:
Network UPS tools - UPS driver controller 2.7.4
Network UPS tools - generic hid driver 0.41 (2.7.4)
USB communication driver 0.33
No matching hid UPS found.

From there, I remembered that this error can be permissions-related so I cd to /etc/sv/upsdrvctl and ran ls - l like you suggested.
Here is the output:
-rwxr-xr-x 1 root root 28 Apr 27 14:49 finish
-rwxr-xr-x 1 root root 141 Apr 27 14:49 run
lrwxrwxrwx 1 root 30 App 27 14:49 supervise -> /run/runit/supervise.upsdrvctl

Also, inside /etc/sv/upsdrvctl/run:
#Network Ups tools - driver control
install -d -m 0770 -o nut -g nut /run/ups
upsdrvctl -D start
exec chpst - b upsdrvctl pause

From here I’m not quite sure what to do. It appears that the correct permissions and everything should be being created, right?

(Kevin Moses) #9

So after I did this, I decided to run:
upsdrvctl - d start
and that worked, so I have the nut driver working on pid 2374, based on top command.
But now I cannot run upsc myups, it doesn’t work.
I get:
Error: connection failure: connection refused.

I think somehow I am supposed to have started the nut-server.service, but that was coming from the arch wiki. Not sure that applies here.

(Kevin Moses) #10

Okay so it looks like I was able to get access to the cyberpower unit by creating a runit for upsd.
So now when I run upsc myups I get expected results.

The only problem that I have now is that every time I try to create a runit service for upsmon, it goes into a never-ending loop.

Here is the loop:
Network UPS tools upsmon 2.7.4

It just keeps saying this, line by line.
In my upsmon I have set only this:
MONITOR myups@localhost 1 my_username password master

The my username and password corresponds to what I have in upsd.users

What’s going on with that???

(Kevin Moses) #11

Okay masato so maybe I solved this:
In your other thread where you were helping another guy out, I see that he added the down command to upsmon.
When I do that, the loop goes away.
So is this exactly what’s supposed to happen, upsmon script only runs when upsd tells it to run those commands?

It don’t seem right though, because when I bring upsmon back up with sudo sv up upsmon, it doesn’t run a shutdown script, only puts me back in a loop:
Network UPS tools upsmon 2.7.4
Network UPS tools upsmon 2.7.4
Network UPS tools upsmon 2.7.4
Network UPS tools upsmon 2.7.4

(Masato the Empty) #12

Create a runit service? You mean you’re enabling the symlinks, right? (since they already exist as part of the package).

Well, OK; if you’ve gotten the first parts running (upsdrvctl and upsd) then let’s look at upsmon. First, you know upsd is working because you can successfully run “upsc myups” and get info back.

Setting upsmon to down isn’t going to solve anything. It’s going to keep it down. That loop stops because it’s not trying to run.

When it is trying to run, it’s failing. This behavior seems to match what would happen when the child process is killed (the unprivileged upsmon run as user “nut” that is forked by the upsmon -D command). The parent exits and runit starts it again, causing you to get the banner message. Repeatedly.

In this case, may be worth leaving the upsmon service down, killing all upsmon instances and running this command in a terminal or VT: “sudo upsmon -D

(Kevin Moses) #13

Okay so I figure it out the problem. I had created the upsd.user, however my password I was using was too long.
That caused me not to be able to start the upsmon service which also means that your suggestion to add sudo would not work, I had no service running.
I’m not sure what the default number that you can have as far as password is concern, but I set mine at nine digits characters and whatever and that seemed to work.
The last thing I need to do is to test the Etc/killpower to see if that works.
I am hoping that it will because I did read in the upsmon file that like you said upsmon splits up into two processes one that is root and the other as user ID.
I’m assuming now that the service is enabled for upsmon and I have a PID that the root process will run the killpower sequence.

(Kevin Moses) #14

Okay, upsmon -c fsd works, the system shutdown, but when I restart it I start getting a banner message, a previous instance of upsmon is already running, try to restart upsmon.

Looking at top I have:
Upsmon running as root and as nut simultaneously. I tried to kill root version, but I don’t think that’s the problem because then upsmon -c fsd doesn’t work.
I’m trying to figure out if I need to set Run_as_user nut in upsmon or if I need to get rid of the nut upsmon process.

(Kevin Moses) #15

The things I have tried: I tried to add the flags -u myups then -p myups to upsmon run. Doesn’t work.
I tried to remove upsmon from /var/services. Doesn’t work.

This is getting to be a real hassle. Like it every step there’s something. G4rrrrrrrr4r

(Masato the Empty) #16

the only real problem I know of is how upsmon works with runit. It tries to kill the parent process, but by some odd mechanism, it causes another parent process to spawn, and the previous child goes defunct but is not terminated.

Hence, restarting the upsmon service will always fail. You have to stop the service, then kill the lingering processes (sometimes there will only be one).

However, if you’re now able to run upsmon, you should be able to do everything via the included runit services. upsmon should start normally on a cold- or reboot. It should only have problems when you need to stop/restart the service for some reason. That requires you to kill the lingering processes before starting it up again.

No changes to the upsmon runit file should be necessary if all your config files are working… The plain old “exec upsmon -D” with no further arguments should do the trick (user/pass were in your config file)

(Kevin Moses) #17

I have a quick question when you reboot up your system does upsdrvctl “hang”

Everytime I boot up my system, it does and I have to do a ctrl + c to get to the login prompt.

(Masato the Empty) #18

No problems here.
I wonder, before you have a getty/login, is ctrl-c really sending a SIGINT to something? What happens if you just press enter?

Is upsdrvctl really hung? What’s the status of the other services when you are able to log in? They can’t start if upsdrvctl isn’t up and running.

I never log into VT 1 unless in single mode. I tend to use VTs 4, 5, and 6 (in addition to X on 7; I normally use a DM)

(Kevin Moses) #19

Well pressing enter works. I just don’t understand why upsdrvctl won’t resolve after runit starts it from a cold process.

It does the same thing when I run sudo sv start upsdrvctl. The service is started but it hangs until I press enter.
What is weird is that it appears that upsdrvctl is started AFTER I get the void login.

Runit has completed initialization, running stage 2…
-runit:leave stage: /etc/runit/1
-runit:leave stage: /etc/runit/2
runsvchdir default current.
Void 4.16.14_1 (voidbox) (tty1)
Void login: Network Ups tools - ups driver controller 2.7.4
Network Ups tools - generic hid driver 0.41 (2.7.4)
USB communication driver 0.33

I press enter:

Void 4.16.14_1 (voidbox) (tty1)

Voidbox login:

(Kevin Moses) #20

I just don’t know why when you initially start the service either by ln -s /etc/sv/upsdrvctl /var/service or by rebooting the computer, the process hangs.
But after the process is loaded, I can run:
sudo sv start upsdrvctl, or sudo sv stop upsdrvctl or I can run sudo sv start upsd the same.

My process hangs when I try to create a symlink to /var/service or I reboot.
As long as it is loaded, wherever it goes, everything works properly.
It makes no sense to me.