Check if a reboot is required after installing Linux updates

RedHat OS family

Applies to: RedHat / CentOS / Amazon Linux

Don’t forget that you 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).

If you install 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 reboot is not needed, and 1 if it is, so it is perfect to use in a script.

An example:

root@server1:~> needs-restarting  -r ; echo $?
Core libraries or services have been updated:
  openssl-libs -> 1:1.0.1e-60.el7_3.1
  systemd -> 219-30.el7_3.9

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

More information:

Debian OS family

Applies to: Debian / Ubuntu

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

if [ -f /var/run/reboot-required ]; then
  echo 'reboot required'

Packages with pending changes that require a restart are listed in:

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

Helper tool

There is a Debian/Ubuntu program that will not only check for services that need a restart but also restart them for you.

sudo apt install needrestart

Running this program without options will attempt to restart all services that have been updated. You can also run this program interactively if you want to see which services need to be restarted and choose only the one’s that you want to install.

sudo needrestart -r i

Suse OS family

Applies to: OpenSUSE / SLES

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

sudo zypper ps

WIP Notes