How to check if CentOS / RHEL needs a full reboot

I am using a CentOS/RHEL 6/7/8 server. How do I check from the command line if a reboot is required for my CentOS host? How do I check if a host powered by CentOS Enterprise Linux needs to reboot after running the yum update command?

We can quickly check if CentOS / RHEL needs reboot using a command-line option. Let us find out whether a full CentOS Linux reboot is needed and which Linux services need to be restarted on the host. We are going use the needs-restarting command. It report a list of process ids of programs that started running before they or some component they use were updated.
Tutorial requirements
Operating system/appRHEL/CentOS Linux
Root privileges required Yes
Difficulty Easy (rss)
Estimated completion time 5m
Table of contents

Installing needs-restarting utility to check if CentOS / RHEL needs reboot

Run the following yum command:
# yum whatprovides needs-restarting

Outputs from my CentOS 8:

CentOS-8 - AppStream                                                                                                                                                                              3.3 MB/s | 5.8 MB     00:01    
CentOS-8 - Base                                                                                                                                                                                   2.1 MB/s | 2.2 MB     00:01    
CentOS-8 - Extras                                                                                                                                                                                  14 kB/s | 7.3 kB     00:00    
yum-utils-4.0.12-3.el8.noarch : Yum-utils CLI compatibility layer
Repo        : BaseOS
Matched from:
Filename    : /usr/bin/needs-restarting

Now all you have to do is install yum-utils as follows:
# yum install yum-utils

Last metadata expiration check: 0:00:47 ago on Tue Sep  8 20:13:44 2020.
Dependencies resolved.
===============================================================================
 Package                      Arch       Version              Repository  Size
===============================================================================
Installing:
 yum-utils                    noarch     4.0.12-3.el8         BaseOS      66 k
Installing dependencies:
 dnf-plugins-core             noarch     4.0.12-3.el8         BaseOS      64 k
 python3-dateutil             noarch     1:2.6.1-6.el8        BaseOS     251 k
 python3-dnf-plugins-core     noarch     4.0.12-3.el8         BaseOS     203 k
 python3-six                  noarch     1.11.0-8.el8         BaseOS      38 k
 
Transaction Summary
===============================================================================
Install  5 Packages
 
Total download size: 622 k
Installed size: 1.3 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): python3-dateutil-2.6.1-6.el8.noarch.rpm 1.6 MB/s | 251 kB     00:00    
(2/5): python3-six-1.11.0-8.el8.noarch.rpm     1.3 MB/s |  38 kB     00:00    
(3/5): dnf-plugins-core-4.0.12-3.el8.noarch.rp 320 kB/s |  64 kB     00:00    
(4/5): yum-utils-4.0.12-3.el8.noarch.rpm       1.1 MB/s |  66 kB     00:00    
(5/5): python3-dnf-plugins-core-4.0.12-3.el8.n 675 kB/s | 203 kB     00:00    
-------------------------------------------------------------------------------
Total                                          898 kB/s | 622 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                       1/1 
  Installing       : python3-six-1.11.0-8.el8.noarch                       1/5 
  Installing       : python3-dateutil-1:2.6.1-6.el8.noarch                 2/5 
  Installing       : python3-dnf-plugins-core-4.0.12-3.el8.noarch          3/5 
  Installing       : dnf-plugins-core-4.0.12-3.el8.noarch                  4/5 
  Installing       : yum-utils-4.0.12-3.el8.noarch                         5/5 
  Running scriptlet: yum-utils-4.0.12-3.el8.noarch                         5/5 
  Verifying        : dnf-plugins-core-4.0.12-3.el8.noarch                  1/5 
  Verifying        : python3-dateutil-1:2.6.1-6.el8.noarch                 2/5 
  Verifying        : python3-dnf-plugins-core-4.0.12-3.el8.noarch          3/5 
  Verifying        : python3-six-1.11.0-8.el8.noarch                       4/5 
  Verifying        : yum-utils-4.0.12-3.el8.noarch                         5/5 
 
Installed:
  dnf-plugins-core-4.0.12-3.el8.noarch                                         
  python3-dateutil-1:2.6.1-6.el8.noarch                                        
  python3-dnf-plugins-core-4.0.12-3.el8.noarch                                 
  python3-six-1.11.0-8.el8.noarch                                              
  yum-utils-4.0.12-3.el8.noarch                                                
 
Complete!
[root@centos-8 ~]#

Checking if CentOS needs a full reboot

The syntax is:
# needs-restarting
Check for exit status (1 means reboot needed and 0 means reboot not required):
echo $?

How to check whether a full reboot is required for CentOS host

Make sure the following command tell whether a full reboot is required (exit code 1) or not (exit code 0). The syntax is:
# The -r option not available on CentOS 6 so use the exit status #
# needs-restarting --reboothint
# needs-restarting -r
# echo $? # see exit status #

Sample session:

No core libraries or services have been updated.
Reboot is probably not necessary.

Run the following on CentOS 8 to update installed packages for security:
# yum -y update

yum update -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.piconets.webwerks.in
 * extras: mirrors.piconets.webwerks.in
 * updates: mirrors.piconets.webwerks.in
Resolving Dependencies
--> Running transaction check
---> Package curl.x86_64 0:7.29.0-57.el7 will be updated
---> Package curl.x86_64 0:7.29.0-57.el7_8.1 will be an update
---> Package dbus.x86_64 1:1.10.24-13.el7_6 will be updated
---> Package dbus.x86_64 1:1.10.24-14.el7_8 will be an update
---> Package dbus-libs.x86_64 1:1.10.24-13.el7_6 will be updated
---> Package dbus-libs.x86_64 1:1.10.24-14.el7_8 will be an update
---> Package libcurl.x86_64 0:7.29.0-57.el7 will be updated
---> Package libcurl.x86_64 0:7.29.0-57.el7_8.1 will be an update
---> Package systemd.x86_64 0:219-73.el7_8.6 will be updated
---> Package systemd.x86_64 0:219-73.el7_8.9 will be an update
---> Package systemd-libs.x86_64 0:219-73.el7_8.6 will be updated
---> Package systemd-libs.x86_64 0:219-73.el7_8.9 will be an update
--> Finished Dependency Resolution
 
Dependencies Resolved
 
===============================================================================
 Package            Arch         Version                   Repository     Size
===============================================================================
Updating:
 curl               x86_64       7.29.0-57.el7_8.1         updates       271 k
 dbus               x86_64       1:1.10.24-14.el7_8        updates       245 k
 dbus-libs          x86_64       1:1.10.24-14.el7_8        updates       169 k
 libcurl            x86_64       7.29.0-57.el7_8.1         updates       223 k
 systemd            x86_64       219-73.el7_8.9            updates       5.1 M
 systemd-libs       x86_64       219-73.el7_8.9            updates       416 k
 
Transaction Summary
===============================================================================
Upgrade  6 Packages
 
Total download size: 6.4 M
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/6): dbus-1.10.24-14.el7_8.x86_64.rpm                   | 245 kB   00:00     
....
...
......
  Verifying  : systemd-219-73.el7_8.6.x86_64                             12/12 
 
Updated:
  curl.x86_64 0:7.29.0-57.el7_8.1       dbus.x86_64 1:1.10.24-14.el7_8        
  dbus-libs.x86_64 1:1.10.24-14.el7_8   libcurl.x86_64 0:7.29.0-57.el7_8.1    
  systemd.x86_64 0:219-73.el7_8.9       systemd-libs.x86_64 0:219-73.el7_8.9  
 
Complete!

See if a reboot is neeed after installing RHEL or CentOS Linux updates

All you need to do is:
# needs-restarting -r

Core libraries or services have been updated:
  dbus -> 1:1.10.24-14.el7_8
  systemd -> 219-73.el7_8.9

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

More information:
https://access.redhat.com/solutions/27943

Here is how I check if my CentOS 7 box needs reboot:
# needs-restarting
# needs-restarting -r
# needs-restarting -r >/dev/null
# echo $?
# [ $(needs-restarting -r >/dev/null ) ] || echo "Reboot $HOSTNAME to install kernel or core libs."


Related: Reboot CentOS Linux desktop or RHEL server using any one of the following command:
# shutdown -r now
# reboot
# systemctl reboot

Ansible reboot Linux machine or server with playbooks

Conclusion

You learned how to determine if updated binaries that need restarting on a CentOS or RHEL host using the command-line option. To see help, type:
$ needs-restarting --help

This entry is 3 of 3 in the Linux Reboot Tutorial series. Keep reading the rest of the series:
  1. Find out if my Ubuntu/Debian Linux server needs a reboot
  2. OpenSUSE install lsof package to get rid of 'zypper ps' errors
  3. Check if CentOS / RHEL needs a full reboot
🐧 If you liked this page, please support my work on Patreon or with a donation.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • Sven Krämer Sep 9, 2020 @ 7:10

    All commands are also working in Fedora 32.

  • Daniel Pereira Sep 10, 2020 @ 1:43

    Or you could just use `dnf needs-restarting -r` which requires no additional packages

  • Jorge Sep 12, 2020 @ 18:18

    Hi Vivek,

    On CentOS 6 needs-restarting do not have the -r or --reboothint options available, at the top of your post you mention CentOS 6, so that might not be correct:

    needs-restarting -r
    Usage: 
        needs-restarting: Report a list of process ids of programs that started 
                        running before they or some component they use were updated.    
    needs-restarting: error: no such option: -r
    

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.