Skip to main content

How does systemd ask units to reload configuration? [Resolved]

I was reading the manpage for systemctl reload and found this sentence about reload.

reload PATTERN...
    Asks all units listed on the command line to reload their
    configuration.

http://man7.org/linux/man-pages/man1/systemctl.1.html

How does systemd do that? What API does systemd use to ask a unit to reload its configuration?

I also found reload-or-restart.

 reload-or-restart PATTERN...
     Reload one or more units if they support it. If not, restart them
     instead.

How does systemd know if the unit supports reload?


Question Credit: 425nesp
Question Reference
Asked October 6, 2019
Posted Under: Network
20 views
1 Answers

Here's what the man page systemd.service says about reloading:

       ExecReload=
           Commands to execute to trigger a configuration reload in the 
           service. This argument takes multiple command lines, following
           the same scheme as described for ExecStart= above. Use of
           this setting is optional. Specifier and environment variable
           substitution is supported here following the same scheme as
           for ExecStart=.

           One additional, special environment variable is set: if known,
           $MAINPID is set to the main process of the daemon, and may
           be used for command lines like the following:

               /bin/kill -HUP $MAINPID

           Note however that reloading a daemon by sending a signal
           (as with the example line above) is usually not a good
           choice, because this is an asynchronous operation and hence
           not suitable to order reloads of multiple services against
           each other. It is strongly recommended to set ExecReload=
           to a command that not only triggers a configuration reload
           of the daemon, but also synchronously waits for it to complete.

(The only way to know that systemd.service is the correct man page to look in was to Google for ExecReload, a string I guessed after digging through Systemd's source code.)


credit: Throw Away Account
Answered October 6, 2019
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA