RedHat OS family
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-utilspackage, you can use a command called
You can use it both for checking if a full reboot is required because of kernel or core libraries updates (using the
-roption), or what services need to be restarted (using the
0if reboot is not needed, and
1if it is, so it is perfect to use in a script.
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: https://access.redhat.com/solutions/27943 1
Debian OS family
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 libssl1.0.0
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
zypper natively has the ability to find services and processes that need to be restarted.
sudo zypper ps