174

I have a service that stopped suddenly. I tried to restart that service but failed and was asked to run: systemctl daemon-reload.

What does it exactly do? What is a daemon-reload?

0

3 Answers 3

117

man systemctl says:

daemon-reload

Reload systemd manager configuration. This will rerun all generators (see systemd.generator(7)), reload all unit files, and recreate the entire dependency tree. While the daemon is being reloaded, all sockets systemd listens on behalf of user configuration will stay accessible.

This command should not be confused with the reload command.

So, it's a "soft" reload, essentially; taking changed configurations from filesystem and regenerating dependency trees.

Consequently, systemd.generator states:

Generators are small binaries that live in /usr/lib/systemd/user-generators/ and other directories listed above. systemd(1) will execute those binaries very early at bootup and at configuration reload time — before unit files are loaded. Generators can dynamically generate unit files or create symbolic links to unit files to add additional dependencies, thus extending or overriding existing definitions. Their main purpose is to convert configuration files that are not native unit files dynamically into native unit files.

Generators are loaded from a set of paths determined during compilation, listed above. System and user generators are loaded from directories with names ending in system-generators/ and user-generators/, respectively. Generators found in directories listed earlier override the ones with the same name in directories lower in the list. A symlink to /dev/null or an empty file can be used to mask a generator, thereby preventing it from running. Please note that the order of the two directories with the highest priority is reversed with respect to the unit load path and generators in /run overwrite those in /etc.

After installing new generators or updating the configuration, systemctl daemon-reload may be executed. This will delete the previous configuration created by generators, re-run all generators, and cause systemd to reload units from disk. See systemctl(1) for more information.

4
  • I am wondering why would one want to put this in a daily cron job see github.com/cri-o/cri-o/issues/2584 . he claims it is an overflow issue in systemd github.com/systemd/systemd/issues/11809 I would like to understand why it is needed and why it happened
    – Hend
    Mar 25, 2020 at 11:07
  • 1
    I haven't looked into this in great detail, I could only speculate that the idea there is to try to force a "soft reload" using cron. I'm not sure if that's necessary, or how effective that is. The bug you linked to is shown to have been fixed. So, maybe they use older version of systemd. Again, merely speculating. You could try asking a new question with those references and a pointer to this question perhaps.
    – ILMostro_7
    Mar 26, 2020 at 22:50
  • 1
    I'm wondering if it would be okay to always automatically systemctl daemon-reload run when inotify detects that some config file has been modified... Jan 23, 2021 at 15:56
  • 1
    @MikkoRantalainen It is conceivable that you sometimes you might need the ability to change two or more service files and have the changes take effect together as a single, "atomic" operation. With the inotify scheme you propose, that becomes impossible. So you would need a way to opt out of the inotify detection when necessary.
    – telcoM
    Aug 22 at 6:11
1

On logoff or just prior to a reboot, I would use a simple test of the /etc/fstab. I would just check its timestamp from a previously saved value. You could also remember a previously calculated sha1 sum.

A script to include as mentioned, will go a long way to not forgetting to run the daemon reload.

1

If you change /lib/systemd/system/<servicename>.service and restart via

systemctl restart <servicename>.service

it will not load the new settings unless you do a systemctl daemon-reload. Instead, it will just restart the old cached settings with no changes.

This has burned us many times. People just restart service but forget that it does not reload the changes.

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Mar 17 at 15:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .