How to find if the Linux OS needs Reboot after Patching/Updates




In this post, I am going to share how to identify if servers/services need a reboot after OS patching.

RHEL/OEL/Centos

We might need to reboot because of core library updates, at least if it is glibc. (And also, services may need to be restarted after updates).

With the yum-utils package, you can use a command called needs-restarting.

You can use it both for checking if a full reboot is required because of kernel or core libraries updates (using the -r option), or what services need to be restarted (using the -s option).

needs-restarting -r returns 0 if a reboot is not needed, and 1 if it is, so it is perfect to use in a script.

Example

[himanshu@fundb ~]$ needs-restarting -r
No core libraries or services have been updated.
Reboot is probably not necessary.

Now let's do an OS update

yum update -y

Once completed, please check the restart required or not.

[root@fundb ~]# needs-restarting -r
Core libraries or services have been updated:
  kernel -> 3.10.0-1160.25.1.el7
  glibc -> 2.17-324.0.1.el7_9
  systemd -> 219-78.0.3.el7_9.3
  openssl-libs -> 1:1.0.2k-21.0.1.el7_9
  linux-firmware -> 999:20201217-999.7.git7455a360.el7

Reboot is required to ensure that your system benefits from these updates.


Debian/Ubuntu/Linux Mint

The system needs a reboot if the file /var/run/reboot-required exists and can be checked as follows:

#!/bin/bash
if [ -f /var/run/reboot-required ]; then
  echo 'reboot required'
fi
Packages with pending changes that require a restart are listed in:

root@system:/root# cat /var/run/reboot-required.pkgs
libso2.0.0

OpenSUSE/SLES(Suse Linux)

zypper natively has the ability to find services and processes that need to be restarted.

sudo zypper ps



If you like please follow and comment