From bf6eab34b4ed07fb586049e007ebb70b18746347 Mon Sep 17 00:00:00 2001 From: Martin Osvald Date: Fri, 1 Aug 2025 13:07:00 +0200 Subject: [PATCH] Support for sending startup notifications to systemd Resolves: RHEL-102532 --- kea-dhcp4.service | 1 + kea-dhcp6.service | 1 + kea-sd-daemon.patch | 189 ++++++++++++++++++++++++++++++++++++++++++++ kea.spec | 7 +- 4 files changed, 197 insertions(+), 1 deletion(-) create mode 100644 kea-sd-daemon.patch diff --git a/kea-dhcp4.service b/kea-dhcp4.service index a0ae770..dc7a57a 100644 --- a/kea-dhcp4.service +++ b/kea-dhcp4.service @@ -6,6 +6,7 @@ After=network-online.target After=time-sync.target [Service] +Type=notify User=kea AmbientCapabilities=CAP_NET_BIND_SERVICE CAP_NET_RAW Environment="KEA_PIDFILE_DIR=/run/kea" diff --git a/kea-dhcp6.service b/kea-dhcp6.service index f7b7835..35872dc 100644 --- a/kea-dhcp6.service +++ b/kea-dhcp6.service @@ -6,6 +6,7 @@ After=network-online.target After=time-sync.target [Service] +Type=notify User=kea AmbientCapabilities=CAP_NET_BIND_SERVICE Environment="KEA_PIDFILE_DIR=/run/kea" diff --git a/kea-sd-daemon.patch b/kea-sd-daemon.patch new file mode 100644 index 0000000..a3a9ea0 --- /dev/null +++ b/kea-sd-daemon.patch @@ -0,0 +1,189 @@ +diff --git a/config-report.sh.in b/config-report.sh.in +index 1af984e..ddd4b62 100755 +--- a/config-report.sh.in ++++ b/config-report.sh.in +@@ -105,6 +105,18 @@ Netconf: no + HERE_DOCUMENT + fi + ++if test '@HAVE_LIBSYSTEMD_DAEMON@' != 'no'; then ++add_to_report < + ++#ifdef HAVE_LIBSYSTEMD_DAEMON ++#include ++#endif ++ + using namespace isc::data; + using namespace isc::dhcp; + using namespace isc::process; +@@ -290,6 +294,13 @@ main(int argc, char* argv[]) { + + // Tell the admin we are ready to process packets + LOG_INFO(dhcp4_logger, DHCP4_STARTED).arg(VERSION); ++#ifdef HAVE_LIBSYSTEMD_DAEMON ++ // Notify systemd about the same ++ sd_notifyf(0, "READY=1\n" ++ "STATUS=Dispatching packets...\n" ++ "MAINPID=%lu", ++ (unsigned long) getpid()); ++#endif + + // And run the main loop of the server. + ret = server.run(); +diff --git a/src/bin/dhcp4/meson.build b/src/bin/dhcp4/meson.build +index 3dac320..e8cacb9 100644 +--- a/src/bin/dhcp4/meson.build ++++ b/src/bin/dhcp4/meson.build +@@ -1,3 +1,8 @@ ++kea_dhcp4_dependencies = [CRYPTO_DEP] ++if SYSTEMD_DEP.found() ++ kea_dhcp4_dependencies += [SYSTEMD_DEP] ++endif ++ + dhcp4_lib = static_library( + 'dhcp4', + 'client_handler.cc', +@@ -16,7 +21,7 @@ dhcp4_lib = static_library( + kea_dhcp4 = executable( + 'kea-dhcp4', + 'main.cc', +- dependencies: [CRYPTO_DEP], ++ dependencies: kea_dhcp4_dependencies, + include_directories: [include_directories('.')] + INCLUDES, + install: true, + install_dir: SBINDIR, +diff --git a/src/bin/dhcp6/main.cc b/src/bin/dhcp6/main.cc +index 7ab1999..abac799 100644 +--- a/src/bin/dhcp6/main.cc ++++ b/src/bin/dhcp6/main.cc +@@ -24,6 +24,10 @@ + + #include + ++#ifdef HAVE_LIBSYSTEMD_DAEMON ++#include ++#endif ++ + using namespace isc::data; + using namespace isc::dhcp; + using namespace isc::process; +@@ -290,6 +294,13 @@ main(int argc, char* argv[]) { + + // Tell the admin we are ready to process packets + LOG_INFO(dhcp6_logger, DHCP6_STARTED).arg(VERSION); ++#ifdef HAVE_LIBSYSTEMD_DAEMON ++ // Notify systemd about the same ++ sd_notifyf(0, "READY=1\n" ++ "STATUS=Dispatching packets...\n" ++ "MAINPID=%lu", ++ (unsigned long) getpid()); ++#endif + + // And run the main loop of the server. + ret = server.run(); +diff --git a/src/bin/dhcp6/meson.build b/src/bin/dhcp6/meson.build +index de60fbf..04a22a9 100644 +--- a/src/bin/dhcp6/meson.build ++++ b/src/bin/dhcp6/meson.build +@@ -1,3 +1,8 @@ ++kea_dhcp6_dependencies = [CRYPTO_DEP] ++if SYSTEMD_DEP.found() ++ kea_dhcp6_dependencies += [SYSTEMD_DEP] ++endif ++ + dhcp6_lib = static_library( + 'dhcp6', + 'client_handler.cc', +@@ -17,7 +22,7 @@ dhcp6_lib = static_library( + kea_dhcp6 = executable( + 'kea-dhcp6', + 'main.cc', +- dependencies: [CRYPTO_DEP], ++ dependencies: kea_dhcp6_dependencies, + include_directories: [include_directories('.')] + INCLUDES, + install: true, + install_dir: SBINDIR, diff --git a/kea.spec b/kea.spec index 29921ee..6ef5aa1 100644 --- a/kea.spec +++ b/kea.spec @@ -33,6 +33,8 @@ Source14: kea-ctrl-agent.service Source15: systemd-tmpfiles.conf Source16: systemd-sysusers.conf +Patch1: kea-sd-daemon.patch + BuildRequires: boost-devel # %%meson -D crypto=openssl BuildRequires: openssl-devel @@ -50,6 +52,8 @@ BuildRequires: libpq-devel %else BuildRequires: postgresql-server-devel %endif +# %%meson -D systemd=enabled +BuildRequires: systemd-devel %if %{with sysrepo} # %%meson -D netconf=enabled BuildRequires: sysrepo-devel @@ -161,7 +165,8 @@ export KEA_PKG_TYPE_IN_CONFIGURE="rpm" -D crypto=openssl \ -D krb5=enabled \ -D mysql=enabled \ - -D postgresql=enabled + -D postgresql=enabled \ + -D systemd=enabled %meson_build %meson_build doc