# Help with nut (upsmon)

## mhodak

I am not able to get upsmon going correctly with nut. I can see UPS status fine, i.e. upsc gives the info, but calling shutdown sequence is a problem. Part of it is that I do not understand how should things work and why do I need additional users (nut and another one for monitoring).

Here is what I have in /etc/nut/upsd.users:

```
[upsmonuser]

                password  = my_p4ss

                upsmon master

```

That seems OK to me, but I am not sure if the user "upsmonuser" should be a UNIX system user (in which case it should be created) or if it is just a fake user for nut. I have not created the user, maybe that is the problem.

Next, here is /etc/nut/upsmon.conf

```
MONITOR myups 1 upsmonuser my_p4ss master

MINSUPPLIES 1

SHUTDOWNCMD "/sbin/shutdown -h +0"

POLLFREQ 5

POLLFREQALERT 5

HOSTSYNC 15

DEADTIME 15

POWERDOWNFLAG /etc/nut/killpower

NOTIFYFLAG ONBATT      SYSLOG+WALL

 NOTIFYFLAG LOWBATT     SYSLOG+WALL

 NOTIFYFLAG FSD SYSLOG+WALL

RBWARNTIME 43200

NOCOMMWARNTIME 300

FINALDELAY 5
```

I added "MONITOR myups 1 upsmonuser my_p4ss master" and three NOTIFYFLAG messages, the rest was default.

AFAIK, this should be correct for setting up upsmon. But when I cut power to my UPS, there is no message in terminals, although /var/log/messages says "wall: user nut broadcasted 1 lines (22 chars)", but nothing appears in any terminal. I would like to test shutdown, but by default nut waits until battery becomes low, which is stupid for testing. Waiting for 1 minute after ups loses power should be much better, but I do not see a good way to set it up.

So, basically, how do I know that upsmon is working? Do I need to create an extra user for that? And ho to easily test that the whole setup works?

Overall, I am pretty frustrated with nut. I understand what it tries to do, but even after reading its manual I do not understand how it works.

Thank you for your help.

----------

## Anon-E-moose

You would probably need to add /etc/init.d/nut.powerfail to the default to have it shutdown on power fail.

I've seen a message in my terminal when I had power blink for a moment, but I had a term open at the time.

Otherwise it won't open a terminal to tell you about it, as far as I know.  (wall should write to ALL console/terms)

I do keep a daily log of the ups using usplog (I think it talks to upsmon, but that's a guess), the log zeroed at midnight.

Do a "man upsmon" for further info.

And yes the documentation leaves a lot to be desired.  :Wink: 

----------

## mhodak

Actually, I have tried adding /etc/init.d/nut.powerfail to default startup, but it would shutdown the machine, which was quite unpleasant  :Smile: . Had to use chroot to remove it from startup.

----------

## Anon-E-moose

From the /etc/init.d/nut.powerfail

 *Quote:*   

> if [ -f /etc/killpower -o -f /etc/nut/killpower ]; then

 

It should only trigger a shutdown if either of those two files are present

(gentoo should be using /etc/nut/killpower)

----------

## mhodak

It looks like that according to the script, but when I start the service (I have just tested that), it kills my machine and none of the files are present. Actually, it is not a clean shutdown, machine stays powered up but it is not responsive. Maybe there is something wrong with the script or it should not be started automatically, that is nut will call it when power is off.

----------

## Anon-E-moose

```
    if [ -f /etc/killpower -o -f /etc/nut/killpower ]; then

        UPS_CTL=/sbin/upsdrvctl

        UPS_POWERDOWN="${UPS_CTL} shutdown"

    elif [ -f /etc/apcupsd/powerfail ]; then

        UPS_CTL=/sbin/apcupsd

        UPS_POWERDOWN="${UPS_CTL} --killpower"

    else

        ewarn "UPS powerfail script scheduled, but no poweroff commands found."

        return 0

    fi
```

It should only take one of three paths, shutdown, apcupsd (if running apc ups) or simply tell you that no poweroff script was found.

But you may be correct that it shouldn't be autostarted, I don't have it that way, but haven't had a long running power failure to see what happens.

----------

## mhodak

Not sure why it kills my machine, but according to bug #266804 (when the script was added), it is meant to run as a part of shutdown to turn off UPS. 

Back to upsmon. How do you handle user there, is it an actual system user or just something that exists within upsmon?

----------

## Anon-E-moose

As far as I know the user in upsd.user is some name you decide to use. 

The name I picked isn't a user on my system.

You should be seeing messages in any terminal that is open (X) or any one of the console terms.

Edit to add: It does use "wall" which is part of sysvinit, if using systemd then I don't know if cmd is available.

As far as testing, the UPS itself may have a test option, where it sends a signal to the operating system.

----------

## AndCycle

I know this is outdated reply, but this thread is high in google ranking,

here is the correct answer,

nut.powerfail should be in "shutdown" level, not "default",

```
rc-update add nut.powerfail shutdown

```

```
        nut.powerfail |              shutdown

```

----------

