dnf needs-restarting -r: reboot needed after update? (Rocky 9)
After a dnf update on Rocky 9, dnf needs-restarting -r exits 1 when a reboot is required; this covers which packages count and how to find services to restart.
Core libraries or services have been updated since boot-up: * glibc Reboot is required to fully utilize these updates.More information: https://access.redhat.com/solutions/27943If dnf needs-restarting -r exits with 1, you need to reboot. The text above means a core package such as glibc or the kernel was updated after boot.
Finishing dnf update does not mean running processes use the new libraries. Anything already running keeps the old glibc in memory. On Rocky Linux 9, dnf needs-restarting reports this state. The text above is real output after updating glibc in a container.
[1] Check the plugin is installed. needs-restarting ships in dnf-plugins-core. Install it if it is missing.
$ rpm -q dnf-plugins-core || sudo dnf install dnf-plugins-corednf-plugins-core-4.3.0-26.el9.noarch[2] Look at the baseline. If nothing core changed since the last boot, -r answers like this and exits 0. The official docs define the exit code of -r (--reboothint) as "reboot needed: 1, not needed: 0" (dnf-plugins-core docs).
$ dnf needs-restarting -r; echo rc=$?No core libraries or services have been updated since boot-up.Reboot should not be necessary.rc=0[3] Update, then ask again. The test upgraded glibc and openssl-libs.
$ sudo dnf -y update glibc openssl-libs >/dev/null; echo rc=$?$ rpm -q glibc openssl-libsrc=0glibc-2.34-283.el9_8.x86_64openssl-libs-3.5.8-2.el9_8.x86_64$ dnf needs-restarting -r; echo rc=$?Core libraries or services have been updated since boot-up: * glibc Reboot is required to fully utilize these updates.More information: https://access.redhat.com/solutions/27943rc=1glibc is listed and the exit code is 1. That value is the signal for scripts. Exit code 1 is not an error. A script with set -e stops on any non-zero value, so catch it with || true or read rc=$? yourself. openssl-libs was not listed this time. The docs do not name the packages, but the source has a fixed list. The dnf-plugins-core 4.3.0 that was tested lists kernel, kernel-rt, glibc, linux-firmware, systemd, dbus, dbus-broker and dbus-daemon (4.3.0 source); newer source adds kernel-core and microcode_ctl, ten in all (source). -r returns 1 when one of these packages was installed after boot. So other libraries such as openssl-libs are not covered by -r: even with exit code 0, services that use that library still need a restart.
[4] You can extend the list of packages that call for a reboot. Per the docs, put package names one per line in a .conf file under /etc/dnf/plugins/needs-restarting.d/. After adding vim-minimal and updating it, it appears in the list.
$ sudo mkdir -p /etc/dnf/plugins/needs-restarting.d$ echo vim-minimal | sudo tee /etc/dnf/plugins/needs-restarting.d/custom.conf$ sudo dnf -y update vim-minimal >/dev/null; rpm -q vim-minimal$ dnf needs-restarting -r; echo rc=$?vim-minimal-8.2.2637-26.el9_8.23.x86_64Core libraries or services have been updated since boot-up: * glibc * vim-minimal Reboot is required to fully utilize these updates.More information: https://access.redhat.com/solutions/27943rc=1To roll back, delete that file. A test package left on the list raises the reboot signal on every update.
[5] To restart services instead of rebooting, use -s (services) and the default mode (processes). Per the docs, -s lists only the affected systemd services and -u looks only at the current user's processes.
$ dnf needs-restarting$ dnf needs-restarting -sIn the test container, after step 3, both commands printed nothing and exited 0. A process started before the update was still holding the old libc, as /proc showed:
$ sudo grep -l 'libc.so.6 (deleted)' /proc/[0-9]*/maps 2>/dev/null | cut -d/ -f3 | xargs -r ps -o pid=,lstart=,comm= -p$ grep libc.so.6 /proc/<PID>/maps | head -3$ grep -c "(deleted)" /proc/<PID>/maps7db62b152000-7db62b17a000 r--p 00000000 00:32 405214982 /usr/lib64/libc.so.6 (deleted)7db62b17a000-7db62b2ef000 r-xp 00028000 00:32 405214982 /usr/lib64/libc.so.6 (deleted)7db62b2ef000-7db62b347000 r--p 0019d000 00:32 405214982 /usr/lib64/libc.so.6 (deleted)11A mapping marked (deleted) is still using a file that was replaced. So in this test the default mode and -s returned nothing while the process held the old library. Whether that comes from the container or from this version was not determined. What those two commands print on a real server was not tested, so also check for (deleted) mappings when deciding what to restart. The first command above finds every process holding the old libc (in the container: 0 before the glibc update; afterwards the sleep started earlier and PID 1; output in run/scan.out.txt). On a real server, check the service behind each PID with systemctl status <PID> and restart it.
[6] If -r returns 1 (glibc, the kernel, systemd and the like), rebooting is the answer; do it in a quiet window. Restarting services is for libraries -r does not cover (openssl-libs and so on), and -r keeps returning 1 after such a restart until you reboot, so a script that alarms on that exit code keeps alarming. glibc, systemd and dbus are used by PID 1 and nearly every process, so a service restart cannot replace the reboot. No restart command was run in this test. If -r returns 0 but step [5] finds services holding an old library, restart just those with systemctl restart <service>.
Where checks get confusing
- Exit code 1 from
dnf needs-restarting -rmeans "reboot needed", not failure. - In this test the default mode and
-swere empty while a process still held the old library (the/proccheck above). - Kernel updates were not tested; the container has no kernel package.
- The image was Rocky 9.3 and the repositories already served 9.8-series (
el9_8) packages.