Restart Systemd ..

2jNb...Zvcv
11 Jan 2024
96

How to restart systemd without rebooting Linux when critical libraries installed


  1. Applying security updates for systemd and other apps on Linux

First thing first apply update using your package manger such as apt command/apt-get command/dnf command/yum command/apk command/zypper command and so on. For instance:

$ sudo command apt update && sudo apt upgrade
$ sudo command dnf update
$ sudo command zypper ref && sudo zypper up
$ doas command apk update && doas apk upgrade


How to get a list of services that needs restarting on Linux and systemd


Now that updates are applied, we can check if CentOS / RHEL / Fedora needs a complete reboot and service restart:

$ sudo needs-restarting


We can use the needrestart command to checks which daemons need to be restarted after library upgrades on a Debian or Ubuntu/Mint Linux:

$ sudo needrestart


On OpenSUSE/Suse Enterprise Linux, we can install the lsof package and use the zypper ps to list all such services that need restarting:

$ sudo zypper ps


So I need to restart nginx, firewalld, systemd-udevd and other services on OpenSUSE Linux. Unfortunately, not every Linux distro has tools to determine such a state. Fear not. We can use the lsof command to list all such services. The syntax is:

$ sudo lsof | grep -i deleted$ 
$ sudo lsof | grep -i 'lib-name'$ 
$ sudo lsof | grep libssl


Restarting systemd without rebooting Linux system

We use the systemctl command as follows to restart services one-by-one:

$ sudo systemctl restart nginx$ 
$ sudo systemctl restart firewalld


We can use bash for loop as follows:

for s in systemd-udevd  firewalld  polkit  sshd nginx
do
    sudo systemctl restart "$s"
done


Verify it again using commands as per your distro or the lsof command:

# Debian based distro #
$ sudo needrestart
# RHEL based distro #
$ sudo needs-restarting
# OpenSUSE/SUSE Enterprise Linux #
$ sudo zypper ps
# All other Linux distro #
$ sudo lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u


systemd


Unluckily systemd still not restarted as it got PID # 1. How do we deal with that?

How to restart systemd with PID # 1 without rebooting Linux box

Run the following command

$ sudo systemctl daemon-reexec


And verify it again:

$ sudo lsof | grep 'DEL.*lib' | cut -f 1 -d ' ' | sort -u


Get fast shipping, movies & more with Amazon Prime

Start free trial

Enjoy this blog? Subscribe to Barss

6 Comments