Merge branch '1176-add-support-for-sd_notify-interface-to-better-integrate-on-linux' into 'main'

Add support for reporting status via sd_notify()

Closes #1176

See merge request isc-projects/bind9!5514
This commit is contained in:
Petr Špaček 2022-09-15 08:17:20 +00:00
commit 0ffa8d1a9c
5 changed files with 75 additions and 4 deletions

View file

@ -1,3 +1,5 @@
5971. [func] Add libsystemd sd_notify() support. [GL #1176]
5970. [func] Log the reason why a query was refused. [GL !6669]
5969. [bug] DNSSEC signing statistics failed to identify the

View file

@ -14,6 +14,7 @@ AM_CPPFLAGS += \
$(MAXMINDDB_CFLAGS) \
$(DNSTAP_CFLAGS) \
$(LIBUV_CFLAGS) \
$(LIBSYSTEMD_CFLAGS) \
$(ZLIB_CFLAGS)
if HAVE_JSON_C
@ -109,7 +110,7 @@ named_LDADD = \
$(MAXMINDDB_LIBS) \
$(DNSTAP_LIBS) \
$(LIBUV_LIBS) \
$(LIBXML2_LIBS) \
$(LIBSYSTEMD_LIBS) \
$(ZLIB_LIBS)
if HAVE_JSON_C
@ -121,3 +122,8 @@ if HAVE_LIBNGHTTP2
named_LDADD += \
$(LIBNGHTTP2_LIBS)
endif HAVE_LIBNGHTTP2
if HAVE_LIBXML2
named_LDADD += \
$(LIBXML2_LIBS)
endif HAVE_LIBXML2

View file

@ -28,6 +28,10 @@
#include <fstrm.h>
#endif
#ifdef HAVE_LIBSYSTEMD
#include <systemd/sd-daemon.h>
#endif
#include <isc/aes.h>
#include <isc/attributes.h>
#include <isc/base64.h>
@ -215,11 +219,12 @@
} while (0)
#define CHECKFATAL(op, msg) \
do { \
{ \
result = (op); \
if (result != ISC_R_SUCCESS) \
if (result != ISC_R_SUCCESS) { \
fatal(server, msg, result); \
} while (0)
} \
}
/*%
* Maximum ADB size for views that share a cache. Use this limit to suppress
@ -9912,6 +9917,15 @@ view_loaded(void *arg) {
"FIPS mode is %s",
FIPS_mode() ? "enabled" : "disabled");
#endif /* ifdef HAVE_FIPS_MODE */
#if HAVE_LIBSYSTEMD
sd_notifyf(0,
"READY=1\n"
"STATUS=running\n"
"MAINPID=%" PRId64 "\n",
(int64_t)getpid());
#endif /* HAVE_LIBSYSTEMD */
atomic_store(&server->reload_status, NAMED_RELOAD_DONE);
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
@ -10085,6 +10099,10 @@ shutdown_server(isc_task_t *task, isc_event_t *event) {
isc_event_free(&event);
#if HAVE_LIBSYSTEMD
sd_notify(0, "STOPPING=1\n");
#endif /* HAVE_LIBSYSTEMD */
/*
* We need to shutdown the interface before going
* exclusive (which would pause the netmgr).
@ -10526,6 +10544,10 @@ reload(named_server_t *server) {
isc_result_t result;
atomic_store(&server->reload_status, NAMED_RELOAD_IN_PROGRESS);
#if HAVE_LIBSYSTEMD
sd_notify(0, "RELOADING=1\n"
"STATUS=reload command received\n");
#endif /* HAVE_LIBSYSTEMD */
CHECK(loadconfig(server));
@ -10542,6 +10564,12 @@ reload(named_server_t *server) {
atomic_store(&server->reload_status, NAMED_RELOAD_FAILED);
}
cleanup:
#if HAVE_LIBSYSTEMD
sd_notifyf(0,
"READY=1\n"
"STATUS=reload command finished: %s\n",
isc_result_totext(result));
#endif /* HAVE_LIBSYSTEMD */
return (result);
}
@ -10903,6 +10931,10 @@ isc_result_t
named_server_reconfigcommand(named_server_t *server) {
isc_result_t result;
atomic_store(&server->reload_status, NAMED_RELOAD_IN_PROGRESS);
#if HAVE_LIBSYSTEMD
sd_notify(0, "RELOADING=1\n"
"STATUS=reconfig command received\n");
#endif /* HAVE_LIBSYSTEMD */
CHECK(loadconfig(server));
@ -10919,6 +10951,12 @@ named_server_reconfigcommand(named_server_t *server) {
atomic_store(&server->reload_status, NAMED_RELOAD_FAILED);
}
cleanup:
#if HAVE_LIBSYSTEMD
sd_notifyf(0,
"READY=1\n"
"STATUS=reconfig command finished: %s\n",
isc_result_totext(result));
#endif /* HAVE_LIBSYSTEMD */
return (result);
}

View file

@ -924,6 +924,26 @@ AS_CASE([$with_zlib],
AC_SUBST([ZLIB_CFLAGS])
AC_SUBST([ZLIB_LIBS])
#
# was --with-libsystemd specified?
#
# [pairwise: --with-libsystemd=auto, --with-libsystemd=yes, --without-libsystemd]
AC_ARG_WITH([libsystemd],
[AS_HELP_STRING([--with-libsystemd],
[build with libsystemd integration [default=auto]])],
[], [with_libsystemd=auto])
AS_CASE([$with_libsystemd],
[no],[],
[auto],[PKG_CHECK_MODULES([LIBSYSTEMD], [libsystemd],
[AC_DEFINE([HAVE_LIBSYSTEMD], [1], [Use libsystemd library])],
[:])],
[yes],[PKG_CHECK_MODULES([LIBSYSTEMD], [libsystemd],
[AC_DEFINE([HAVE_LIBSYSTEMD], [1], [Use libsystemd library])])],
[AC_MSG_ERROR([Specifying libsystemd installation path is not supported, adjust PKG_CONFIG_PATH instead])])
AC_SUBST([LIBSYSTEMD_CFLAGS])
AC_SUBST([LIBSYSTEMD_LIBS])
#
# Check if the system supports glibc-compatible backtrace() function.
#

View file

@ -33,6 +33,11 @@ New Features
a given server support DNS COOKIE. It can also be used to force all
non DNS COOKIE responses to fall back to TCP. :gl:`#2295`
- Add libsystemd sd_notify() integration that allows the ``named`` to report
status to the supervisor. This allows the systemd to wait until ``named`` is
fully started before starting other services that depend on name resolution.
:gl:`#1176`
Removed Features
~~~~~~~~~~~~~~~~