named support of a systemd unit with 'notify-reload' service type is incomplete
Summary
systemctl reload named.service
doesn't work because of an incomplete sd_notify(3) message sent by named
.
Related: #4374
BIND version used
BIND 9.19.18-dev (Development Release) id:d0a03db
Steps to reproduce
When using a systemd unit with the Type=notify-reload
option (see below) and trying to reload named
using systemctl reload named.service
, the reloading process hangs and eventually fails with a timeout.
$ sudo systemctl reload named.service
Job for named.service failed.
See "systemctl status named.service" and "journalctl -xeu named.service" for details.
Logs (see below) show that the reload operation was in fact successful (i.e. named
received and processed the SIGHUP signal), but systemd was likely not correctly notified:
What is the current bug behavior?
systemctl reload named.service
fails.
What is the expected correct behavior?
systemctl reload named.service
to be successful.
Relevant configuration files
The named.service
unit file:
[Unit]
After=network.target
Wants=nss-lookup.target
Before=nss-lookup.target
[Service]
Type=notify-reload
NotifyAccess=all
ExecStart=/opt/dev/sbin/named -u named
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Relevant logs and/or screenshots
Oct 19 11:47:44 systemd[1]: Reloading named.service...
Oct 19 11:47:44 named[1010507]: received SIGHUP signal to reload zones
Oct 19 11:47:44 named[1010507]: loading configuration from '/opt/dev/etc/named.conf'
Oct 19 11:47:44 named[1010507]: looking for GeoIP2 databases in '/usr/share/GeoIP'
...
Oct 19 11:49:14 systemd[1]: named.service: Reload operation timed out. Killing reload process.
Oct 19 11:49:14 systemd[1]: Reload failed for named.service.
Possible fixes
The systemd.service manual page says that the sd_notify(3) message with the "RELOADING=1" field should also contain a "MONOTONIC_USEC=" field with the current CLOCK_MONOTONIC time.
The following experimental patch solves the issue for me:
diff --git a/bin/named/server.c b/bin/named/server.c
index f23e28547a..90bdcb0fbc 100644
--- a/bin/named/server.c
+++ b/bin/named/server.c
@@ -10287,8 +10287,16 @@ reload(named_server_t *server) {
atomic_store(&server->reload_status, NAMED_RELOAD_IN_PROGRESS);
#if HAVE_LIBSYSTEMD
- sd_notify(0, "RELOADING=1\n"
- "STATUS=reload command received\n");
+ char buf[1024];
+ int n = snprintf(buf, sizeof(buf),
+ "RELOADING=1\n"
+ "MONOTONIC_USEC=%" PRIu64 "\n"
+ "STATUS=reload command received\n",
+ isc_time_monotonic() / 1000);
+
+ if (n > 0 && (size_t)n < sizeof(buf)) {
+ sd_notify(0, buf);
+ }
#endif /* HAVE_LIBSYSTEMD */
CHECK(loadconfig(server));