-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
pid1: add new Type=notify-reload service type for a service reload protocol based on SIGHUP #25916
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
(i guess still needs an integration test) |
54a87be to
6441ff8
Compare
|
Test added. Should be ready for review. |
a521995 to
e5748e5
Compare
190add2 to
6f8d880
Compare
|
bit of bikeshedding, but maybe it would be nicer from the usability point of view to have a separate setting, rather than a different |
the last 10y or so we didn't extend Type=notify in such a major way that we introduced a new type. i don't really see anything coming up for the next 10y in that regard. Hence, if history tells us anything I think it's OK to expose this as type. Note that the many many extensions we did to sd_notify() we always did without intrdoucing a new type (watchdog, fdstore, barrier, …), and I am pretty sure for 99% of future additions this is going to be the same. Just this extension is one of the few that actually touches the state machine of the service, hence it's a bit more involved. Given that with this change the whole state machine of the service is basically exposed via sd_notify() i really can't see anything else coming... |
6f8d880 to
361cd3a
Compare
…reloading And send READY=1 again when we are done with it. We do this not only for "daemon-reload" but also for "daemon-reexec" and "switch-root", since from the perspective of an encapsulating service manager these three operations are not that different.
We are basically already there, just need to add MONOTONIC_USEC= to the RELOADING=1 message, and make sure the message is generated in really all cases.
So close already. Let's add the two missing notifications too. Fixes: systemd#18484
These wrap RELOADING=1 and STOPPING=1 messages. The former is particularly useful, since we want to insert the MONOTONIC_USEC= field into the message automatically, which is easy from C but harder from shell.
361cd3a to
6fee784
Compare
|
@poettering Sorry for late comment. Let me confirm one point. Why the new type |
|
I'm also wondering what warrants the necessity of the new type.
Is this state machine change somewhat relevant to service authors? IIUC, reload behavior could have been buggy when a spontaneous (by the daemon) and PID1-initiated reload coincide. IOW, even with the new type introduced, the old type would still have problems that could be solved with an optional |
We need to know if services implement reload or not, so that we can implement things such as "systemctl reload-or-restart" properly.
Note that most of our own service don#t actually support reloading (they probably should be), hence you'll actually see more |
Well, service authors can drop This is for example interesting for delegated services, because it means pid1 won't ever have to fork anything into the delegated cgroup, just to do a reload. And yeah, services that already implement If an externally triggered reload and one by PID1 happen at the same time this should be entirely fine, they can be coalesced. what pid 1 cares about is one
I don't grok this comment? |
Suppose a service like The service follows the protocol with There can be a race: PID wouldn't know which message is associated with its reload request and which The fix would be for the service to attach I.e. the new could be equivalent to And BC default would be (relying on a possibly unsynced |
|
And yes, MONOTONIC_USEC= I added to deal with the race you describe, if that was the question? otherwise we wouldn't need it.
|
|
I remember 5686391 that was 5 years ago, so by your reasoning, budget for the next new Type= should only be in 2028 :-) Encoding same-but-modified behavior just within the
Ad bike-shedding -- if this weren't just a comment but a PR 1, would it be better? Footnotes
|
commit f74b856 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, in addition to sending a [MONOTONIC_USEC]. We currently still support distros that do not provide systemd 253, so cannot use this new feature, but sending "RELOADING=1 / "READY=1" should at least provide more information to systemd for the time being. This patch: - adds reload notifications to the daemon to notify when the daemon got signaled to reload its configuration see [sd_notify(3)]. - adds a [notifyReady] 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). We can re-implement this using `Type=notify-reload` once we no longer have to support systemd versions before 253. [sd_notify(3)]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#RELOADING=1 [systemd.service(5)]: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Type= [ExecReload]: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#ExecReload= [MONOTONIC_USEC]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#MONOTONIC_USEC=… [systemd#25916]: systemd/systemd#25916 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
commit f74b856 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, in addition to sending a [MONOTONIC_USEC]. We currently still support distros that do not provide systemd 253, so cannot use this new feature, but sending "RELOADING=1 / "READY=1" should at least provide more information to systemd for the time being. This patch: - adds reload notifications to the daemon to notify when the daemon got signaled to reload its configuration see [sd_notify(3)]. - adds a [notifyReady] 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). We can re-implement this using `Type=notify-reload` once we no longer have to support systemd versions before 253. [sd_notify(3)]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#RELOADING=1 [systemd.service(5)]: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Type= [ExecReload]: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#ExecReload= [MONOTONIC_USEC]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#MONOTONIC_USEC=… [systemd#25916]: systemd/systemd#25916 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
commit f74b856 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, in addition to sending a [MONOTONIC_USEC]. We currently still support distros that do not provide systemd 253, so cannot use this new feature, but sending "RELOADING=1 / "READY=1" should at least provide more information to systemd for the time being. This patch: - adds reload notifications to the daemon to notify when the daemon got signaled to reload its configuration see [sd_notify(3)]. - adds a [notifyReady] 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). We can re-implement this using `Type=notify-reload` once we no longer have to support systemd versions before 253. [sd_notify(3)]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#RELOADING=1 [systemd.service(5)]: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Type= [ExecReload]: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#ExecReload= [MONOTONIC_USEC]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#MONOTONIC_USEC=… [systemd#25916]: systemd/systemd#25916 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
commit f74b856 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, in addition to sending a [MONOTONIC_USEC]. We currently still support distros that do not provide systemd 253, so cannot use this new feature, but sending "RELOADING=1 / "READY=1" should at least provide more information to systemd for the time being. This patch: - adds reload notifications to the daemon to notify when the daemon got signaled to reload its configuration see [sd_notify(3)]. - adds a [notifyReady] 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). We can re-implement this using `Type=notify-reload` once we no longer have to support systemd versions before 253. [sd_notify(3)]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#RELOADING=1 [systemd.service(5)]: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Type= [ExecReload]: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#ExecReload= [MONOTONIC_USEC]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#MONOTONIC_USEC=… [systemd#25916]: systemd/systemd#25916 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
As per the `sd_notify` manual: > A field carrying the monotonic timestamp (as per CLOCK_MONOTONIC) formatted > in decimal in μs, when the notification message was generated by the client. > This is typically used in combination with "RELOADING=1", to allow the > service manager to properly synchronize reload cycles. See systemd.service(5) > for details, specifically "Type=notify-reload". Thus this change allows users with a recent systemd to switch to `Type=notify-reload`, should they desire to do so. Correct behavior was verified with a Fedora 39 VM. see systemd/systemd#25916 [wla: the service file should be updated this way:] diff --git a/admin/systemd/haproxy.service.in b/admin/systemd/haproxy.service.in index 22a53d8..8c6dadb5e5 100644 --- a/admin/systemd/haproxy.service.in +++ b/admin/systemd/haproxy.service.in @@ -8,12 +8,11 @@ EnvironmentFile=-/etc/default/haproxy EnvironmentFile=-/etc/sysconfig/haproxy Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid" "EXTRAOPTS=-S /run/haproxy-master.sock" ExecStart=@sbindir@/haproxy -Ws -f $CONFIG -p $PIDFILE $EXTRAOPTS -ExecReload=@sbindir@/haproxy -Ws -f $CONFIG -c $EXTRAOPTS -ExecReload=/bin/kill -USR2 $MAINPID KillMode=mixed Restart=always SuccessExitStatus=143 -Type=notify +Type=notify-reload +ReloadSignal=SIGUSR2 # The following lines leverage SystemD's sandboxing options to provide # defense in depth protection at the expense of restricting some flexibility Signed-off-by: William Lallemand <wlallemand@haproxy.com>
commit f74b856 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, in addition to sending a [MONOTONIC_USEC]. We currently still support distros that do not provide systemd 253, so cannot use this new feature, but sending "RELOADING=1 / "READY=1" should at least provide more information to systemd for the time being. This patch: - adds reload notifications to the daemon to notify when the daemon got signaled to reload its configuration see [sd_notify(3)]. - adds a [notifyReady] 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). We can re-implement this using `Type=notify-reload` once we no longer have to support systemd versions before 253. [sd_notify(3)]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#RELOADING=1 [systemd.service(5)]: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Type= [ExecReload]: https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#ExecReload= [MONOTONIC_USEC]: https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html#MONOTONIC_USEC=… [systemd#25916]: systemd/systemd#25916 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Fixes: #18484 #6162