Skip to main content
Topic: Network UPS Tools (NUT) on Artix (Read 593 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Network UPS Tools (NUT) on Artix

Hello there, I hope I'm not asking a repetitive question here.
I've been using Artix for about a year now, so I'm still learning the ins and outs.
Recently I bought a Uninterruptible Power Supply for my home server since thunderstorms caused multiple power outages in the last few weeks.
On this system I run Artix with kernel 5.12.12 and runit.

Now to use this UPS, I connected it via USB and installed the nut package from the arch community repo, since it's not available in the artix ones.
Then I used the wiki page to configure it, with the usbhid-ups driver.

All went well until the "upsd configuration" section. Here you should enable nut-server.service, but of course that's not simply possible with runit.
In /usr/lib/systemd/system there are now three services: "nut-driver.service" "nut-monitor.service" and "nut-server.service".
nut-server and nut-monitor are explicitly mentioned in the wiki and I assume nut-driver is important as well.

Is there a way to "port" these service files for use with runit, or is it impossible to run such a program anyway?
I'll put the content of these three files below.
Thanks in advance.

Code: [Select]
cat nut-driver.service
Code: [Select]
[Unit]
Description=Network UPS Tools - power device driver controller
After=local-fs.target network.target
StopWhenUnneeded=yes

[Service]
ExecStart=/usr/bin/upsdrvctl start
ExecStop=/usr/bin/upsdrvctl stop
Type=forking

Code: [Select]
cat nut-monitor.service
Code: [Select]
[Unit]
Description=Network UPS Tools - power device monitor and shutdown controller
After=local-fs.target network.target nut-server.service

[Service]
ExecStart=/usr/bin/upsmon
PIDFile=/run/nut/upsmon.pid
Type=forking

[Install]
WantedBy=multi-user.target

Code: [Select]
cat nut-server.service
Code: [Select]
[Unit]
Description=Network UPS Tools - power devices information server
After=local-fs.target network.target nut-driver.service
# We don't Require drivers to be successfully started! This would be
# a change of behavior compared to init SysV, and could prevent from
# accessing successfully started, at least to audit a system.
Wants=nut-driver.service
Before=nut-monitor.service

[Service]
ExecStart=/usr/bin/upsd
Type=forking

[Install]
WantedBy=multi-user.target

 

Re: Network UPS Tools (NUT) on Artix

Reply #1
Hello,
You probably managed to resolve the issue by now.
I am sharing my scripts, maybe they will be useful to someone.

/etc/runit/sv/nutd/run
Code: [Select]
#!/bin/sh
set -e
mkdir -p /run/nut
touch /run/nut/upsd.pid
chown nut:nut /run/nut/upsd.pid
/usr/bin/upsdrvctl start
/usr/bin/upsd
exec chpst -b nutd pause

/etc/runit/sv/nutd/finish
Code: [Select]
#!/bin/sh
set -e
/usr/bin/upsd -c stop
/usr/bin/upsdrvctl stop

/etc/runit/sv/nutmon/run
Code: [Select]
#!/bin/sh
set -e
mkdir -p /run/nut
touch /run/nut/upsmon.pid
chown nut:nut /run/nut/upsmon.pid
/usr/bin/upsmon
exec chpst -b nutmon pause

/etc/runit/sv/nutmon/finish
Code: [Select]
#!/bin/sh
set -e
/usr/bin/upsmon -c stop

Remember to
Quote
chmod 755 <file>
all scripts!

I made two separate services because the nut-server needs the driver but the nut-monitor is independent of the server (for example when network ups is used).
Check which user is used by the nut. The default one is "nut".

Edit 1:
I noticed that there are some issues with supervising nut daemons. I updated scripts, now I am able to stop and start nut daemons on demand.
Once I am satisfied with them I will create a repo with the install script and maybe the AUR package later.

Edit 2:
Bonus script to shutdown UPS (from: https://gitweb.gentoo.org/repo/gentoo.git/tree/sys-power/nut/files/nut.powerfail.initd )

/etc/local.d/ups.stop
Code: [Select]
#!/bin/sh
if [ -f /etc/killpower -o -f /etc/nut/killpower ]; then
    /usr/bin/upsdrvctl shutdown
fi

Edit 3:
https://github.com/patrykknapik/nut-runit