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 calledneeds-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
returns0
if reboot is not needed, and1
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:
https://access.redhat.com/solutions/27943
1
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:
#!/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
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
- https://github.com/atc0005/needs-restart/blob/master/needs-restart.pl
- http://docs.tracer-package.com/en/latest/user-guide/#standard-usage
- https://github.com/stdevel/yum-plugin-needs-restarting/blob/master/needs-restarting.py