Skip to content

[Request] Change or expand restart-required #239

@jeremysherriff

Description

@jeremysherriff

Describe the solution you'd like

Restart-Required was added in #36 and currently just checks for the presence of /var/run/reboot-required - but that seems to be Ubuntu-specific?

If installed, a supplemental method would be to parse the return code of needrestart -p (nagios plugin mode) which exposes a return code of 0|1|2|3 per normal Nagios plugins, depending on the state of the restart required. This package seems to be included by default in Debian-based systems, but the package by itself does not create /var/run/reboot-required.

root@host:~# needrestart -p 2>/dev/null
CRIT - Kernel: 6.8.12-18-pve!=6.8.12-20-pve (!!), Microcode: CURRENT, Services: none, Containers: none, Sessions: none|Kernel=2;0;;0;2 Microcode=0;0;;0;1 Services=0;;0;0 Containers=0;;0;0 Sessions=0;0;;0
root@host:~# echo $?
2

Return codes 1 and 2 indicate a restart requirement (I suggest not trying to differentiate between service restarts and out of date kernels, so both 1 and 2 should indicate a restart requirement). As with all Nagios plugins, a return code of 3 is unknown and should be ignored.

Likewise for modern RHEL and similar systems, dnf needs-restarting -r returns exit code 1 if a restart is required, else 0. Note that -r is required to generate the exit code reliably.

[root@utility ~]# dnf needs-restarting -r
No core libraries or services have been updated since boot-up.
Reboot should not be necessary.
[root@utility ~]# echo $?
0

In both cases, the exit codes provide a more reliable detection method than parsing stdout.

yum is a bit less predictable - yum needs-restarting -r is valid from at least RHEL 6 onwards but unsure how far back it goes.

For Arch (pacman) systems, there's no native option that I am aware of but both needretart and dnf are valid packages to install and expose the same exit codes, if the user wants to install them.

Given that modern RHEL and compatible systems tend to provide both yum and dnf, it may be that simply testing for needrestart and dnf as the appropriate binary to run is the best way to go.

A log message about not finding either during module init would help users identify that there is an optional dependency that they could install - this would be more in line with other modules and provide a positive way of identifying whether the required_restart module will actually ever turn on the binary_sensor.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions