Maintaining system stability and security on Red Hat Enterprise Linux (RHEL), Rocky Linux, AlmaLinux, and Oracle Linux servers often requires regular updates. However, not all updates necessitate an immediate reboot. After applying updates, administrators are tasked with determining if a system restart is needed to complete the installation of critical packages, especially those related to the kernel or other essential services.

This article will walk you through the use of the needs-restarting tool, available via the dnf-utils package, to easily check whether a reboot is required on your RHEL, Rocky Linux, AlmaLinux, or Oracle Linux servers. This approach is a convenient and efficient way to manage reboots and avoid unnecessary downtime.

Why Is It Important to Know When a Reboot Is Required?

Servers running RHEL-based distributions (such as Rocky Linux, AlmaLinux, and Oracle Linux) are often deployed in environments that require high availability, such as web hosting, databases, or cloud services. While applying updates is essential for security and performance, rebooting the system can lead to service interruptions. Therefore, knowing exactly when a restart is required helps in:

  • Minimizing downtime: Reboots are only performed when absolutely necessary.
  • Scheduling maintenance windows: Reboots can be scheduled during low-traffic periods.
  • Preventing potential security risks: Critical updates are fully applied, ensuring that vulnerabilities are patched properly.

What Is the needs-restarting Tool?

The needs-restarting tool is a handy utility included in the dnf-utils package that allows system administrators to check if a reboot is necessary after updating the system. It specifically checks if services or kernel updates require restarting and provides clear feedback, making post-update maintenance easier to manage.

The tool offers two main options:

  1. Listing services that need restarting: It checks for running processes and services that have been updated but not restarted.
  2. Checking if a full system reboot is needed: It determines whether updates affecting critical components, like the kernel, have been installed, in which case a reboot is required.

This tool works on RHEL, Rocky Linux, AlmaLinux, and Oracle Linux as all of these distributions are derived from RHEL and maintain compatibility with its tools and ecosystem.

Installing the dnf-utils Package

Before using needs-restarting, you need to ensure that the dnf-utils package is installed on your system. The process is the same across RHEL, Rocky Linux, AlmaLinux, and Oracle Linux.

Follow these steps:

  1. Open the terminal on your server.
  2. Install the dnf-utils package using the following command: sudo dnf install dnf-utils

Once installed, you’re ready to use the needs-restarting tool.

How to Use needs-restarting

1. Checking if a Reboot Is Required

To quickly check if a reboot is necessary after updating your system, run the following command:

needs-restarting -r

This command performs a system-wide check. If a kernel update or any other critical update has been applied that requires a reboot, the output will clearly state:

Reboot is required.

If no reboot is needed, the command will return no output, meaning you can continue using the system without any disruptions.

2. Listing Services That Need Restarting

In cases where only certain services need to be restarted (but not the entire system), you can use needs-restarting without any options:

needs-restarting

This will list any running services or processes that were updated but are still using old versions. For instance, after running this command, you may see output like this:

1001 : /usr/sbin/httpd
1200 : /usr/sbin/sshd

In this case, httpd (Apache web server) and sshd (Secure Shell service) need to be restarted to apply their respective updates. You can restart these services individually using the following commands:

systemctl restart httpd
systemctl restart sshd

Restarting these services ensures that the latest updates are applied without the need for a full system reboot.

When Should You Use needs-restarting?

  • After running dnf update: Every time you apply updates to your RHEL, Rocky Linux, AlmaLinux, or Oracle Linux server, use needs-restarting to check if a reboot or service restart is required.
  • Before scheduling maintenance: If you’re preparing for a maintenance window, this tool helps you plan by identifying whether a reboot will be necessary.
  • For critical systems: In high-availability environments, minimizing downtime is crucial. Use needs-restarting to avoid unnecessary reboots, only scheduling them when critical updates (like kernel patches) are applied.

Practical Example: Checking for Reboot After an Update

Let’s walk through a typical scenario where you’ve applied updates to a server running RHEL, Rocky Linux, AlmaLinux, or Oracle Linux, and need to determine if a reboot is required.

  1. Apply updates to the system: sudo dnf update -y
  2. Check if a reboot is needed using needs-restarting: needs-restarting -r
    • If the output is Reboot is required, you can then decide to reboot the system immediately or schedule it for later.
  3. Check if any services need restarting:needs-restarting
    • This output will list the services that need to be restarted. You can manually restart each service using systemctl restart <service> as shown above.

Benefits of Using needs-restarting

  • Avoid unnecessary reboots: Only restart your system when a kernel update or similar critical update is applied, saving time and reducing downtime.
  • Efficient service management: Restart services individually if only certain processes require updating, allowing the rest of the system to continue running without disruption.
  • Enhanced security: Ensures that all critical security updates are fully applied without leaving your system vulnerable.

Conclusion

The needs-restarting tool is an essential utility for administrators of RHEL-based distributions, including RHEL, Rocky Linux, AlmaLinux, and Oracle Linux, who want to maintain system uptime and security while managing updates. By using this tool, you can check whether a full system reboot is necessary or if specific services just need to be restarted after applying updates. This allows you to carefully manage reboots and maintain critical services with minimal disruption.

Make sure to incorporate the needs-restarting command into your post-update workflow to ensure that updates are fully applied and your system is running optimally.

Last Update: November 5, 2024

Tagged in:

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,