[Nut-upsuser] NUT with hibernation works only once

Roger Price roger at rogerprice.org
Sun Aug 1 17:02:30 BST 2021


On Sun, 1 Aug 2021, Roger Price wrote:

> * In a NUT induced shutdown, is it the /etc/ups/upsmon.conf directive 
> SHUTDOWNCMD "systemctl hibernate" which causes the system shutdown, or is it 
> the /opt/upssched-cmd-custom clause
>
>  shutdown-timer)
>    echo "Power failure hibernation: Calling upsmon -c fsd, $CHMSG" | wall
>    upsmon -c fsd
>    ;;
>
> If you shut down because of this clause, when does "systemctl hibernate" get 
> executed?

To answer my own question I went to 2.7.4 /clients/upsmon.c where I see line 
1875:

    case 'c':
       if (!strncmp(optarg, "fsd", strlen(optarg)))
          cmd = SIGCMD_FSD;

I followed SIGCMD_FSD and I find in upsmon.c line 1363:

    sa.sa_handler = user_fsd;
    sigaction(SIGCMD_FSD, &sa, NULL);

I followed user_fsd and I find in upsmon.c line 1324:

    static void user_fsd(int sig)
    {
        upslogx(LOG_INFO, "Signal %d: User requested FSD", sig);
        userfsd = 1;
    }

I followed userfsd and I find in upsmon.c line 2002:

    /* check flags from signal handlers */
    if (userfsd)
       forceshutdown();

I followed forceshutdown and I find on upsmon.c line 639:

    /* time expired or all the slaves are gone, so shutdown */
    doshutdown();

I followed doshutdown and I find on upsmon.c line 445

    ret = system(shutdowncmd);

I followed shutdowncmd and I find in upsmon.c line 1063
that shutdowncommand is whatever has been declared with the keyword
SHUTDOWNCMD.

So the answer to my question is that David's /opt/upssched-cmd-custom 
shutdown-timer) clause with command "upsmon -c fsd" effectively executes the 
command specified by the upsmon.conf declaration SHUTDOWNCMD "systemctl 
hibernate", and that the NUT shutdown is clearly a NUT induced hibernation.

It might be useful in a future revision of man 8 upsmon.conf to explain that 
in

   -c _command_
      Send the command _command_ to the existing upsmon process. Valid
      commands are:
            fsd   shutdown all master UPSes (use with caution)

the "use with caution" means execution of whatever has been declared in 
upsmon.conf SHUTDOWNCMD.

It might also be useful to complete the SHUTDOWNCMD declaration with something 
like:

SHUTDOWNCMD "logger -t upssched-cmd-custom \"Calling upsmon -c fsd which calls\
              SHUTDOWNCMD systemctl hibernate\"; systemctl hibernate"

Roger



More information about the Nut-upsuser mailing list