How to Install Needrestart on Fedora 40/39/38 Linux

Needrestart is a highly efficient Linux utility designed to identify processes that need restarting after library updates. Primarily used by system administrators and Linux enthusiasts, this tool streamlines the process of maintaining software dependencies, especially after system updates. In this guide, we’ll demonstrate the straightforward process to install Needrestart on Fedora Linux, ensuring your system’s processes are always up to date with the latest library changes.

Key Features of Needrestart:

  • Automatic Detection: It identifies running processes using outdated libraries or binaries after an update.
  • Flexible Configuration: Offers customizable options to control its behavior and output.
  • Integration with Package Managers: Works seamlessly with various package managers, enhancing its utility.
  • User-Friendly Interface: Provides clear notifications and guidance for restarting services.

As we delve into the installation steps, you’ll find that Needrestart is an indispensable tool for maintaining your Fedora Linux system’s operational efficiency and security. Let’s dive into the installation process.

Install Needrestart on Fedora Linux via DNF

Step 1: Update Fedora Packages Before Needrestart Installation

To ensure your Fedora Linux system operates with the latest software, start by updating existing packages.

Open your terminal and execute:

sudo dnf upgrade --refresh

This command refreshes your package lists and upgrades all installed packages to their latest versions, establishing a stable foundation for installing new software.

Step 2: Install Required Packages for Needrestart

Needrestart relies on several Perl modules to operate efficiently.

Install these dependencies by entering the following:

sudo dnf install perl-JSON perl-Module-ScanDeps perl-Term-ProgressBar perl-Locale-gettext -y

Here, perl-JSON manages JSON data processing, perl-Module-ScanDeps helps in scanning Perl code for dependencies, perl-Term-ProgressBar provides a progress bar in the terminal, and perl-Locale-gettext aids in localization.

Step 3: Install Needrestart via DNF Command

With your system updated and dependencies in place, you’re ready to install Needrestart. Type in the terminal:

sudo dnf install needrestart

This final step installs Needrestart on your Fedora Linux system.

Configure Needrestart on Fedora Linux

Step 1: Editing the Configuration File

Begin by accessing the configuration file. Use this command to open it:

sudo nano /etc/needrestart/needrestart.conf

This opens the Needrestart configuration file in the nano editor, where you can adjust its parameters to your requirements.

Needrestart Configuration File Example on Fedora Linux
Screenshot of Needrestart Configuration on Fedora Linux

Step 2: Customizing Needrestart Settings

In the configuration file, several settings can be adjusted:

Blacklisting Services or Packages

In Needrestart, the blacklisting feature is crucial for specifying which services or packages should not be automatically restarted. This is particularly useful in environments where critical services must maintain uptime or require manual restart intervention.

To blacklist a service, add its name to the configuration array. For instance, to blacklist a service named ‘blacklisted-service-name’:

$nrconf{blacklist} = qw(blacklisted-service-name);

Setting Verbosity Level

Verbosity level in Needrestart controls the detail of output during its operation. A lower verbosity level (e.g., 1) means less detailed output, suitable for routine checks where only essential information is needed. Conversely, a higher verbosity level provides more detailed insights, which can be helpful for troubleshooting or detailed monitoring.

To set verbosity to a basic level:

$nrconf{verbosity} = 1;

Choosing Operation Mode

Needrestart’s operation mode determines how it interacts with the user or system during execution. The ‘interactive’ mode prompts the user for input on restarting services, while ‘batch’ mode automates this process without user intervention. ‘List’ mode, on the other hand, lists processes needing a restart without taking any action.

To set the mode to interactive:

$nrconf{mode} = 'interactive';

For example, to blacklist Apache HTTP Server (httpd) and set a higher verbosity level:

$nrconf{blacklist} = qw(httpd);
$nrconf{verbosity} = 3;

Step 3: Additional Configuration Options

Adjusting Notification Settings

Notification settings in Needrestart allow you to manage how and to whom notifications are sent. Disabling notifications ($nrconf{notify} = 0;) can be helpful to in automated or non-interactive environments where such alerts are unnecessary. Specifying users or groups for notifications can help direct information to relevant parties in a team or organization.

To disable notifications:

$nrconf{notify} = 0;
$nrconf{notify_user} = undef;
$nrconf{notify_group} = undef;

Defining Custom Restart Commands

Customizing the restart command gives you flexibility in how services are restarted. This can be particularly useful if you have specific requirements or scripts that should run instead of the default restart process.

For example, to set a custom command for restarting services:

$nrconf{restart} = '/usr/sbin/service %s restart';

After configuring these settings, save and exit the file to apply your changes effectively. This step is crucial for the customizations to take effect.

Using Needrestart on Fedora Linux

Step 1: Checking for Required Restarts

Execute the following command to initiate a system check:

sudo needrestart

This command scans your Fedora Linux system, identifying services, applications, and kernel modules that necessitate a restart. This is typically required after software updates or system changes that affect these components.

Step 2: Restarting Services and Applications

Needrestart provides interactive prompts to guide you through the restart process. You have the option to restart all detected services and applications, or you can choose specific ones. For instance, to restart only the Apache HTTP Server (httpd), input ‘httpd’ at the prompt and confirm your choice.

Batch Mode for Restarting

For automated restarts without manual input, use batch mode:

sudo needrestart -b

In this mode, Needrestart automatically restarts all identified services and applications without user interaction. This is ideal for scripts or automated maintenance tasks where manual input is not feasible.

List Mode for Reviewing Restart Requirements

To view which services and applications need a restart without actually performing these restarts, use the list mode:

sudo needrestart -l

List mode generates a report detailing all components that would benefit from a restart. This is useful for planning and audit purposes, especially when evaluating the impact of recent updates or changes.

Automating Needrestart with systemd on Fedora Linux

Step 1: Create a New systemd Service File

Begin by crafting a systemd service file. Open it using a text editor like Nano:

sudo nano /etc/systemd/system/needrestart.service

Insert the following configuration:

[Unit]
Description=Needrestart Service
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/bin/needrestart -b

[Install]
WantedBy=multi-user.target

This setup defines a one-shot service, which runs Needrestart in batch mode (-b), automatically restarting services without manual intervention.

Step 2: Create a New systemd Timer File

To schedule regular Needrestart runs, create a systemd timer file:

sudo nano /etc/systemd/system/needrestart.timer

Add this content to automate Needrestart execution:

[Unit]
Description=Run needrestart periodically

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

This timer is configured to trigger the Needrestart service daily. You can modify the OnCalendar parameter to alter the execution frequency according to your needs. After editing, save and close the file.

Step 3: Enable and Start the Needrestart Timer

Activate and initiate the Needrestart timer using:

sudo systemctl enable --now needrestart.timer

This command not only starts the timer but also ensures it’s enabled at boot. As a result, Needrestart will automatically execute at your set interval, maintaining your Fedora Linux system in an optimal state with minimal manual intervention.

Conclusion: Installing Needrestart on Fedora Linux

In this guide, we’ve walked through the steps of installing, configuring, and automating Needrestart on Fedora Linux. This powerful utility is essential for keeping your system updated and secure by efficiently managing necessary restarts of services and applications. Whether you’re a seasoned sysadmin or a curious Linux user, Needrestart streamlines the process of maintaining system stability and security. The ability to automate it with systemd adds an extra layer of convenience, ensuring that your system self-manages its updates seamlessly. Remember to tailor Needrestart’s settings to fit your specific needs and keep your Fedora Linux system running smoothly and securely.

Leave a Comment