commit f74b856e1ac2805fe48ceb52bc83cd7a3cec870c added an [ExecReload] to
the systemd unit, which allows users to signal the daemon to reload its
config through systemd (`systemctl reload docker.service`).
While reloading works, systemd expects the `ExecReload` command to be
synchronous, so that it knows when the reload completes, and can account
for this when managing dependent services.
> Note however that reloading a daemon by enqueuing a signal (...) is usually
> not a good choice, because this is an asynchronous operation and hence not
> suitable when ordering reloads of multiple services against each other.
Systemd 253 introduced a new Type (Type=notify-reload, see [systemd#25916]),
which allows setting a "ReloadSignal" instead, if the service supports
it by including a [MONOTONIC_USEC] value in its "RELOADING=1"
notifications.
This patch:
- adds reload notifications to the daemon to notify when the daemon got
signaled to reload its configuration see [sd_notify(3)].
- appends a [MONOTONIC_USEC] value to the reload notification to support
systemd 253's notify-reload protocol. This is backwards-compatible
with older systemd releases as the systemd service manager ignores
unknown assignments in notifications.
- adds a `notifyReady` callback to notify when the reload finished,
which we currently send regardless if the reload was successful or
failed (which could be due to an invalid config).
[ExecReload]: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#ExecReload=
[systemd#25916]: https://github.com/systemd/systemd/pull/25916
[MONOTONIC_USEC]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#MONOTONIC_USEC=…
[sd_notify(3)]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#RELOADING=1
Signed-off-by: Cory Snider <csnider@mirantis.com>
Co-authored-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
| ... | ... |
@@ -521,6 +521,13 @@ func (cli *daemonCLI) reloadConfig() {
|
| 521 | 521 |
} |
| 522 | 522 |
} |
| 523 | 523 |
|
| 524 |
+ // On Linux, we use sd_notify to indicate we're reloading config. We send |
|
| 525 |
+ // this signal as early as possible to let systemd know we're reloading, |
|
| 526 |
+ // but must signal "ready" after this completes (even on failure), which |
|
| 527 |
+ // is done by the reload function defined above. |
|
| 528 |
+ done := notifyReloading() |
|
| 529 |
+ defer done() |
|
| 530 |
+ |
|
| 524 | 531 |
if err := config.Reload(*cli.configFile, cli.flags, reload); err != nil {
|
| 525 | 532 |
log.G(ctx).WithError(err).Error("Error reloading configuration")
|
| 526 | 533 |
return |
| ... | ... |
@@ -11,6 +11,10 @@ func preNotifyReady() error {
|
| 11 | 11 |
func notifyReady() {
|
| 12 | 12 |
} |
| 13 | 13 |
|
| 14 |
+// notifyReloading sends a message to the host when the server got signaled to |
|
| 15 |
+// reloading its configuration. It is a no-op on FreeBSD. |
|
| 16 |
+func notifyReloading() func() { return func() {} }
|
|
| 17 |
+ |
|
| 14 | 18 |
// notifyStopping sends a message to the host when the server is shutting down |
| 15 | 19 |
func notifyStopping() {
|
| 16 | 20 |
} |
| ... | ... |
@@ -58,6 +58,25 @@ func notifyStopping() {
|
| 58 | 58 |
_, _ = systemdDaemon.SdNotify(false, systemdDaemon.SdNotifyStopping) |
| 59 | 59 |
} |
| 60 | 60 |
|
| 61 |
+// notifyReloading sends a message to the host when the server got signaled to |
|
| 62 |
+// reloading its configuration, see [sd_notify(3)]. The server should be running |
|
| 63 |
+// as a systemd unit with "Type=notify" or "Type=notify-reload" (see |
|
| 64 |
+// [systemd.service(5)]). |
|
| 65 |
+// |
|
| 66 |
+// notifyReloading returns a callback that must be called after reloading completes |
|
| 67 |
+// (either successfully or unsuccessfully) to send [notifyReady]. |
|
| 68 |
+// |
|
| 69 |
+// [sd_notify(3)]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#RELOADING=1 |
|
| 70 |
+// [systemd.service(5)]: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Type= |
|
| 71 |
+func notifyReloading() (done func()) {
|
|
| 72 |
+ sent, _ := systemdDaemon.SdNotify(false, systemdDaemon.SdNotifyReloading+"\n"+systemdDaemon.SdNotifyMonotonicUsec()) |
|
| 73 |
+ if !sent {
|
|
| 74 |
+ // Nothing to do if no reloading event was sent. |
|
| 75 |
+ return func() {}
|
|
| 76 |
+ } |
|
| 77 |
+ return notifyReady |
|
| 78 |
+} |
|
| 79 |
+ |
|
| 61 | 80 |
func validateCPURealtimeOptions(cfg *config.Config) error {
|
| 62 | 81 |
if cfg.CPURealtimePeriod == 0 && cfg.CPURealtimeRuntime == 0 {
|
| 63 | 82 |
return nil |
| ... | ... |
@@ -56,6 +56,10 @@ func preNotifyReady() error {
|
| 56 | 56 |
func notifyReady() {
|
| 57 | 57 |
} |
| 58 | 58 |
|
| 59 |
+// notifyReloading sends a message to the host when the server got signaled to |
|
| 60 |
+// reloading its configuration. It is a no-op on Windows. |
|
| 61 |
+func notifyReloading() func() { return func() {} }
|
|
| 62 |
+ |
|
| 59 | 63 |
// notifyStopping sends a message to the host when the server is shutting down |
| 60 | 64 |
func notifyStopping() {
|
| 61 | 65 |
} |