You are not logged in.

#1 2019-03-18 04:24:37

itsmattson
Member
Registered: 2018-11-22
Posts: 9

[SOLVED] NUT AUR package query regarding nutshutdown script

Hi all,

I noticed today that the /usr/lib/systemd/system-shutdown/nutshutdown script contains the following command: /usr/bin/upsmon -K >/dev/null 2>&1 && /usr/bin/upsdrvctl shutdown

My issue is that I don't seem to get the desired result when I run /usr/bin/upsmon -K manually which makes me wonder how/if the second command is run at all - maybe it isn't.

According to man upsmon the -K option will "Test for the shutdown flag. If it exists and contains the magic string from upsmon, then upsmon will exit with EXIT_SUCCESS. Any other condition will make upsmon exit with EXIT_FAILURE.". The magic string is upsmon-shutdown-file as POWERDOWNFLAG file contents.

When I manually run upsmon -K I get the same output whether the POWERDOWNFLAG file exists (with the magic string) or not. I'm trying to understand why.

A lot of people online seem to instead use " if (test -f /etc/killpower)", instead of upsmon -K, where /etc/killpower is the POWERDOWNFLAG's default value. Page 27/86 of the NUT User Manual on the official website also seems to advocate using the test -f method in their shutdown script example. Still, I'd like to understand how upsmon -K should be behaving as it doesn't seem to do anything regardless of whether the POWERDOWNFLAG exists or whether it doesn't.

Thanks in advance! smile

Last edited by itsmattson (2019-03-20 13:37:30)

Offline

#2 2019-03-18 05:47:22

itsmattson
Member
Registered: 2018-11-22
Posts: 9

Re: [SOLVED] NUT AUR package query regarding nutshutdown script

For the sake of testing, I ran the below with the POWERDOWNFLAG file (/etc/killpower) there, with the magic string, and without and both times it exited with failure.

#!/bin/zsh

/usr/bin/upsmon -K >/dev/null 2>&1

if [ $? -eq 0 ]
then
  echo "Exiting with 0 - Success"
else
  echo "Exiting with 1 - Failed"
fi

Offline

#3 2019-03-20 13:36:59

itsmattson
Member
Registered: 2018-11-22
Posts: 9

Re: [SOLVED] NUT AUR package query regarding nutshutdown script

Hi all, this is solved now. Posting my thoughts in case anyone else wonders the same thing.

I noticed that the -K option for upsmon requires upsmon to not already be running. If it's not running and you pass the -K option, it'll tell you if the POWERDOWNFLAG file is set or not. That's why I got the 1 / EXIT_FAILURE code in the above shell script. It returned the right results after i stopped nut-monitor.service.

I think why it works in the nutshutdown script is because by the time it's run in the nutshutdown script, upsmon has been killed already by the shutdown so when nutshutdown runs the command it doesn't complain that upsmon is already running and exits cleanly with 0 / EXIT_SUCCESS code and proceeds with the /usr/bin/upsdrvctl shutdown command.

Offline

Board footer

Powered by FluxBB