1. Introduction

Keeping a Linux system up to date is a common administrative task. The installation of a new package changes shared libraries or executables of running processes. Thus, we should restart all services and daemons which use older versions of these files.

In this tutorial, we’ll learn how to check which services need to be restarted after a system update under Fedora and Ubuntu.

2. Fedora

With Fedora, we can use the needs-restarting command. The command is installed by default. It provides redirection to the dnf plugin of the same name, with the syntax:

dnf needs-restarting [-u] [-r] [-s]

The needs-restarting command tries to determine which processes make use of files provided by the updated packages.

2.1. Processes That Need to Be Restarted

After starting the command without any option, we’re going to obtain the list of affected processes, with their PIDs and names:

$ sudo needs-restarting
1 : /usr/lib/systemd/systemd rhgb --system --deserialize 28 
577 : /usr/lib/systemd/systemd-resolved 
579 : /sbin/auditd 
604 : /usr/libexec/low-memory-monitor 
# ...
23352 : /usr/lib64/firefox/firefox -contentproc -childID 33 -isForBrowser -prefsLen 29040 -prefMapSize 232544 -jsInitLen 240056 -parentBuildID 20230411150914 -appDir /usr/lib64/firefox/browser {3b91571f-f123-447d-b32a-5ebc48bdafbb} 22102 tab 
23379 : /usr/lib64/firefox/firefox -contentproc -childID 34 -isForBrowser -prefsLen 29040 -prefMapSize 232544 -jsInitLen 240056 -parentBuildID 20230411150914 -appDir /usr/lib64/firefox/browser {fa2e82b3-c9c6-496e-bbc9-7435ac34c3f3} 22102 tab 

2.2. A Quick Check With -r Option

With the -r switch, we’ll list libraries and services which have been updated:

$ sudo needs-restarting -r
Core libraries or services have been updated since boot-up:
  * dbus
  * dbus-broker
  * dbus-daemon
  * glibc
  * kernel
  * linux-firmware
  * systemd
Reboot is required to fully utilize these updates.
More information: https://access.redhat.com/solutions/27943

Additionally, only with this option the command provides a meaningful exit code. Thus, 0 means no reboot is needed, while 1 means the reboot is required. So, let’s read the exit code $? after the update:

$ sudo needs-restarting -r
# ...
Reboot is required to fully utilize these updates.
More information: https://access.redhat.com/solutions/27943
$ echo $?

Otherwise, we’re going to get:

$ sudo needs-restarting -r
No core libraries or services have been updated since boot-up.
Reboot should not be necessary.
$ echo $?

2.3. Services to Restart With -s Option

Let’s list all services which require a restart with the -s switch:

$ sudo needs-restarting -s
# ...
# ...

2.4. User’s Processes With -u Option

Finally, with the -u switch, we narrow the search to the current user:

$ needs-restarting -u
1280 : /usr/lib/systemd/systemd --user 
1311 : /usr/bin/gnome-keyring-daemon --daemonize --login 
1325 : /usr/libexec/gdm-wayland-session /usr/bin/gnome-session 
# ...
23574 : /usr/lib64/firefox/firefox -contentproc -childID 36 -isForBrowser -prefsLen 29040 -prefMapSize 232544 -jsInitLen 240056 -parentBuildID 20230411150914 -appDir /usr/lib64/firefox/browser {6a9ecb86-080a-4dec-85ed-bb8862974d6c} 22102 tab 

3. Ubuntu

With Ubuntu, the presence of the reboot-required file indicates if a reboot is necessary. So, let’s update our system and read this file:

$ sudo cat /var/run/reboot-required
*** System restart required ***

Let’s find the additional information about packages that call for restart in the reboot-required.pkgs file:

$ cat /var/run/reboot-required.pkgs

Usually, both files are touched by the package maintainer after successfully installing the package.

For more details about processes and services demanding restart, we can use two commands: needrestart and checkrestart.

4. The needrestart Command

The needrestart command comes in the package of the same name. With it, we can check which services need restarting. The command takes a bunch of options for completing various tasks:

needrestart [-(v|q)] [-n] [-c <cfg>] [-r <mode>] [-f  <fe>]  [-u <ui>] [-(b|p)] [-kl]

We can run the command whether regular or sudo user.

4.1. Listing Affected Processes

Let’s issue the command without any option to list processes touched by the upgrade:

$ needrestart
Scanning processes...                                                           
Your outdated processes:
at-spi-bus-laun[1694], at-spi2-registr[1809], dbus-daemon[1703, 1544],
 evolution-addre[1831], evolution-alarm[1918], evolution-calen[1787],
 evolution-sourc[1768], gdm-wayland-ses[1609], gjs[13808],
 gnome-calendar[7601], gnome-session-b[1675, 1612], gnome-session-c[1658],
 gnome-shell[1695], gnome-shell-cal[1758], gnome-terminal-[4466],
 goa-daemon[1781], goa-identity-se[1797], gsd-a11y-settin[1834],
 gsd-color[1837], gsd-datetime[1840], gsd-housekeepin[1842],
 gsd-keyboard[1845], gsd-media-keys[1846], gsd-power[1847], gsd-printer[1973],
 gsd-print-notif[1848], gsd-rfkill[1849], gsd-screensaver[1850],
 gsd-sharing[1851], gsd-smartcard[1861], gsd-sound[1866], gsd-wacom[1867],
 gsd-xsettings[3306], gvfsd-metadata[2140], gvfs-udisks2-vo[1716],
 ibus-extension-[1967], ibus-x11[3332], pipewire[1529], pipewire-media-[1530],
 pulseaudio[1531], systemd[1522], tracker-miner-f[1597], update-notifier[3358],
 xdg-desktop-por[1868, 2080, 2169], xdg-document-po[1569], Xwayland[3299]

As a result, we’ve got the list of the daemon processes owned by the current user. Then, let’s apply the -v switch to learn the reason for restart:

$ needrestart -v
[main] eval /etc/needrestart/needrestart.conf
[main] needrestart v3.5
[main] running in user mode
[Core] Using UI 'NeedRestart::UI::stdio'...
[main] systemd detected
[main] #1522 uses obsolete binary /usr/lib/systemd/systemd
# ...
[main] #1531 uses obsolete binary /usr/bin/pulseaudio
# ...
[main] #4466 uses deleted /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.13
Your outdated processes:
# ...
 gnome-shell[1695], gnome-shell-cal[1758], gnome-terminal-[4466],
# ...
 pulseaudio[1531], systemd[1522], tracker-miner-f[1597], update-notifier[3358],
# ...

So, the pulseaudio process with PID 1531 uses obsolete binary /usr/bin/pulseaudio, while gnome-terminal with PID 4466 depends on deleted shared library /usr/lib/x86_64-linux-gnu/libxml2.so.2.9.13.

4.2. Checking for the Kernel’s Upgrade

Now, let’s use the -k option to check for the obsolete kernel version:

$ needrestart -k
Scanning linux images...                                                        

Pending kernel upgrade!

Running kernel version:

  The currently running kernel version is not the expected kernel version

Restarting the system to load the new kernel will not be handled automatically,
so you should consider rebooting. [Return]

4.3. Listing Services to Restart

Next, with the -l option, we can look for services that use obsolete libraries:

$ sudo needrestart -l
Scanning processes...                                                           
Scanning candidates...                                                          

Restarting services...
Service restarts being deferred:
 systemctl restart NetworkManager.service
 systemctl restart gdm.service
 systemctl restart gdm3.service
 systemctl restart networkd-dispatcher.service
 systemctl restart systemd-logind.service
 systemctl restart unattended-upgrades.service
 systemctl restart [email protected]
 systemctl restart wpa_supplicant.service

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

4.4. needrestart for Sudoers

When starting the command as a sudo user, we’ll immediately go to the textual UI with the information about the pending kernel upgrade:

$ sudo needrestart
needrestart kernel

After confirming this message, we’ll find ourselves in the daemon menu:

needrestart services

Now we can select the process for restarting with the Space key – it’ll be indicated by the star symbol.

5. The checkrestart Command

Another command is checkrestart. We can install it from the debian-goodies package. Let’s learn its syntax:

checkrestart [ -hvpanmt ] [ -b blacklist_file ] [ -i package_name ] [ -e pid ]

Again, the command offers us many options. Contrary to needrestart, we can run the command with sudo only.

5.1. Listing Processes

Let’s ask for information about the processes which need to be restarted. By running the command without any options, we’ll get a huge amount of details:

$ sudo checkrestart
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
lsof: WARNING: can't stat() fuse.portal file system /run/user/1000/doc
      Output information may be incomplete.
Found 62 processes using old versions of upgraded files
(58 distinct programs)
(27 distinct packages)

First, we’ve got a summary, followed by a long list of services. Let’s continue to study the command’s output:

Of these, 5 seem to contain systemd service definitions or init scripts which can be used to restart them.
The following packages seem to have definitions that could be used
to restart their services:
	784	/usr/sbin/NetworkManager
	796	/usr/bin/networkd-dispatcher
	941	/usr/share/unattended-upgrades/unattended-upgrade-shutdown
	973	/usr/sbin/gdm3
	1512	/usr/libexec/gdm-session-worker
	1609	/usr/libexec/gdm-wayland-session
	1531	/usr/bin/pulseaudio

These are the systemd services:
systemctl restart NetworkManager.service
systemctl restart NetworkManager-wait-online.service
systemctl restart nm-priv-helper.service
systemctl restart NetworkManager-dispatcher.service
systemctl restart networkd-dispatcher.service

These are the initd scripts:
service unattended-upgrades restart
service gdm3 restart
service pulseaudio-enable-autospawn restart

Now we have a list of processes divided by their restart method. First, we have the systemd services or services with the initd script. For example, these are NetworkManager.service or pulseaudio, respectively. Additionally, we’re prompted with ways to restart them – systemctl restart NetworkManager.service or service pulseaudio-enable-autospawn restart.

Let’s resume reading the output to find services without these facilities – 22 in number.

These processes (22) do not seem to have an associated init script to restart them:
# ...
	3299	/usr/bin/Xwayland
	3358	/usr/bin/update-notifier
	4466	/usr/libexec/gnome-terminal-server
# ...

6. Ubuntu – When Everything Is up to Date

So far, we’ve been operating under the assumption that a restart is needed. Now, let’s take a brief look at what is going on when this isn’t the case.

First, the file reboot-required doesn’t exist:

$ cat /var/run/reboot-required
cat: /var/run/reboot-required: No such file or directory

With needrestart, we can do a quick check:

$ needrestart
Scanning processes...

So, we haven’t got the Your outdated processes section in the output.

Next, with the checkrestart command, we’re going to find out:

$ sudo checkrestart
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/1000/gvfs
      Output information may be incomplete.
lsof: WARNING: can't stat() fuse.portal file system /run/user/1000/doc
      Output information may be incomplete.
Found 0 processes using old versions of upgraded files

7. Conclusion

In the article, we learned how to detect if a restart is necessary. We discussed how to handle this situation with Fedora and Ubuntu. In the case of the first system, we used the needs-restarting command. With Ubuntu, we took a look at needrestart and checkrestart commands with similar scope. With all these commands, we obtained a list of processes that required a restart.

Additionally, we made use of Ubunty-specific file reboot-required, the existence of which indicates the need to reboot.

Comments are open for 30 days after publishing a post. For any issues past this date, use the Contact form on the site.