On Mon, 22 May 2023 12:24:15 -0700 Alex Meyer <debbug...@zezax.com> wrote:

Hello,

> I'm running Debian bullseye with systemd. I also have installed mdadm
> and nut-server.
>
> Looking in /lib/systemd/system-shutdown, I see two drop-in files with
> contents as follows:
>
> mdadm.shutdown:
>
> #!/bin/sh
> # We need to ensure all md arrays with external metadata
> # (e.g. IMSM, DDF) are clean before completing the shutdown.
> /sbin/mdadm --wait-clean --scan
>
> nutshutdown:
>
> #!/bin/sh
> /sbin/upsmon -K >/dev/null 2>&1 && /sbin/upsdrvctl shutdown
>
> The man page for systemd-poweroff.service explains that:
>
> All executables in this directory are executed in parallel
>
> This is the problem.

The systemd-shutdown(8) manpage is explicitly saying:

> Shortly before executing the actual system power-off/halt/reboot/kexec, systemd-shutdown will run all executables in /usr/lib/systemd/system-shutdown/. Those executables are called with one argument: either "poweroff", "halt", "reboot", or "kexec", depending on the chosen action. All executables in this directory are executed in parallel, *and execution of the action is not continued before all executables finished*.

That means that, during normal shutdown, even if nutshutdown script exits, mdadm will have time to finish its job of flushing the metadata.

Only in case of a shutdown triggered by the fact that the power of the UPS is low might indeed cause the power to be cut before mdadm has finished.

This could be mitigated by using POWEROFF_WAIT to pause the execution of nutshutdown for several seconds, I think.

There was a problem that could cause the power to be cut if the MODE was set to none in /etc/nut/nut.conf, that has been fixed in 2.8.3-1

Kind regards,

Laurent Bigonville

Reply via email to