Sub topic 8
Deciding When a Reboot or Service Restart Is Needed
Assume you can use a Linux shell and sudo, read systemd service status, and patch a Debian/Ubuntu or RHEL-family test server. This chapter focuses on what to do after packages have been updated.
A package update replaces files on disk. Running processes may still use the old files in memory. A reboot starts every process again, while a service restart replaces only the selected service process.
Reboot or restart?
Use the smallest action that loads the updated code, but do not delay a required reboot indefinitely.
| Situation | Usual action | Reason |
|---|---|---|
| The kernel was updated | Reboot | The running kernel cannot be replaced in place |
| Core libraries such as `glibc` changed | Reboot is often recommended | Many long-running processes may use old libraries |
| A daemon package changed | Restart that service | The daemon must load the new executable or libraries |
| Only documentation or data files changed | Usually no action | Running processes do not use the changed code |
| The package manager explicitly requests a reboot | Schedule a reboot | The distribution has detected an important pending change |
A service restart can interrupt connections. A reboot interrupts the whole server and may affect storage, networking, clustering, and other services. Schedule either action during an appropriate maintenance window.
Check whether Debian or Ubuntu requires a reboot
Debian and Ubuntu commonly create /var/run/reboot-required after updates that need a reboot. The reboot-required.pkgs file usually identifies the packages that caused the request.
if [ -f /var/run/reboot-required ]; then
echo "Reboot required"
cat /var/run/reboot-required.pkgs 2>/dev/null
else
echo "No reboot marker found"
fiThe absence of this file does not prove that every process is using current libraries. A service can still need restarting after its package changes.
Check a RHEL-family server
On RHEL-family systems, dnf needs-restarting -r checks whether a reboot is recommended. Its exit status is useful in scripts: 1 means a reboot is recommended, and 0 means it is not.
sudo dnf needs-restarting -r
status=$?
echo "reboot check exit code: $status"Read the command output before acting. A nonzero result is a recommendation to investigate and schedule a reboot, not a reason to reboot a production system immediately.
Restart affected services safely
First identify the service and inspect its current state. Then restart it and verify that it became active.
sudo systemctl status nginx --no-pager
sudo systemctl restart nginx
sudo systemctl is-active nginx
sudo journalctl -u nginx -n 50 --no-pagerReplace nginx with the service affected by the update. Do not guess a service name from a package name. For example, the openssh-server package normally provides the ssh service, but the exact unit name depends on the distribution.
A package's installation scripts may restart a service automatically. Check the service status and logs after patching rather than assuming that the restart succeeded.
Exercise
An updated web-server package was installed. No reboot marker exists, but the web service is still running the old executable. What should you do?
Show answer
Restart the web service during an approved window, then check its systemd status, recent journal entries, listening ports, and an application health check. A full reboot is unnecessary unless another update requires it.