Can I restart systemd without rebooting?

I’m trying to restart services after a yum update on RHEL 7.4. I could restart every service using systemctl, but needs-restarting from yum utils tells me that I should also restart systemd itself:

# needs-restarting
1 : /usr/lib/systemd/systemd --system --deserialize 21

Can I restart systemd without rebooting the server, and how?

I found a few mentions of systemctl daemon-reload, but this doesn’t make it disappear from the needs-restarting list.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

To restart the daemon, run

systemctl daemon-reexec

This is documented in the systemctl manpage:

Reexecute the systemd manager. This will serialize the manager state, reexecute the process
and deserialize the state again. This command is of little use except for debugging and
package upgrades. Sometimes, it might be helpful as a heavy-weight daemon-reload. While the
daemon is being reexecuted, all sockets systemd listening on behalf of user configuration will
stay accessible.

Unfortunately needs-restarting can’t determine that systemd has actually restarted. systemd execs itself to restart, which doesn’t reset the process’s start time; but needs-restarting compares the executable’s modification time with the process’s start time to determine whether a process needs to be restarted (among other things), and as a result it always considers that systemd needs to be restarted… To determine whether systemd really needs to be restarted, you can check the output of lsof -p1 | grep deleted: systemd uses a library, libsystemd-shared, which is shipped in the same package and is thus upgraded along with the daemon, so if systemd needs to be restarted you’ll see it using a deleted version of the library. If lsof shows no deleted files, systemd doesn’t need to be restarted. (Thanks to Jeff Schaller for the hint!)

Method 2

In my case, I had just upgraded systemd and any systemctl command was failing:

# systemctl daemon-reexec
Failed to reload daemon: Access denied
# systemctl status
Failed to read server status: Access denied

However according to the init manpage, you can do the same thing by sending SIGTERM to the daemon running as PID 1, which worked:
kill -TERM 1

This reloaded the daemon, after which all the systemctl commands started working again.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments