Hi,

I opened a pull request upstream for this: https://github.com/mvo5/unattended-upgrades/pull/478

It follows the approach of Helmut's plugin and of the suggestion of the needrestart author in https://github.com/liske/needrestart/issues/340: unattended-upgrades sets NEEDRESTART_SUSPEND while it runs and calls the needrestart hook once at the end. I put it in unattended-upgrades itself instead of shipping the plugin, so that:

- the hook is taken from DPkg::Post-Invoke and keeps its arguments ("-m u" on Ubuntu);
- it also runs after an exception;
- it is not run when dpkg did not run, nor when a stop was requested. While testing, a "systemctl stop apt-daily-upgrade.service" during a run deadlocked until TimeoutStopSec: needrestart restarted systemd-networkd, which waited for the stop job of apt-daily-upgrade.service (ordered after it), which waited for unattended-upgrades. In these cases needrestart runs with the next package installation, as its pending state is kept.

Results in VMs, with a cron job running "sleep 3600" every minute:

- trixie, needrestart with $nrconf{restart} = 'a', 238 upgrades in 90 steps: cron.service restarted 84 times (up to 5 starts in 10 s) and 511 s with the current code; once and 388 s with the change; - Ubuntu 26.04 with the default configuration, 13 steps: cron.service restarted 12 times, now once.

With the Debian default $nrconf{restart} = 'i', needrestart under unattended-upgrades only lists the services, so the restart loop needs 'a' on Debian, while it happens by default on Ubuntu. Even then the change avoids running needrestart after every step.

Thanks Helmut for the analysis and the plugin.

Let me know if there are any improvements or other adjustments needed. I identified a few things during testing and checked/tested for potential regressions, but I might not have covered everything.

Regards,
Fabio

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to