needs-restarting hangs on RHEL7

On RHEL7, running the command (as sudo) needs-restarting hangs, as does needs-restarting -s while needs-restarting -r comes back within 2 seconds. By "hangs" I mean that it takes a really long time and eventually my SSH session times out. This was working fine until recently. What can I do to investigate the issue (barring "restart'll fix 'er")?

Relevant man page: https://man7.org/linux/man-pages/man1/needs-restarting.1.html

Note that I restarted the server and then needs-restarting completed in a couple of seconds. But this is clearly not ideal.


Solution 1:

needs-restarting --reboothint checks the install date of a handful of packages that Red Hat has decided need a reboot to take effect. kernel and libc, but also TLS libs and systemd. Compare against system boot time, easy.

needs-restarting without the reboot hint option is a much more intensive query. Search through smaps of every running process for file descriptors. Search rpmdb for owning package and check install time against process start time. If --services, search the process for cgroups that look like a systemd service. If you have a large amount of processes, open files, or memory, this will be slow. Or if rpmdb is on slow storage.

A simple solution is to reboot if any packages were updated. Proving that the system can go down and come back up after changes is useful.

Selectively restarting services would reduce reboots. But how are you finding these if needs-restarting bogs down? And when was the last update cycle where you didn't have a kernel to install?