]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Add systemd notify support
authorPieter Lexis <pieter.lexis@powerdns.com>
Tue, 12 Apr 2016 13:41:24 +0000 (15:41 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 12 Apr 2016 20:27:21 +0000 (22:27 +0200)
13 files changed:
build-scripts/build-dnsdist-rpm
build-scripts/debian-dnsdist/control.in
build-scripts/debian-dnsdist/dnsdist.service
build-scripts/debian-dnsdist/rules
pdns/README-dnsdist.md
pdns/dnsdist-lua.cc
pdns/dnsdist.cc
pdns/dnsdistdist/.gitignore
pdns/dnsdistdist/Makefile.am
pdns/dnsdistdist/configure.ac
pdns/dnsdistdist/contrib/dnsdist.service
pdns/dnsdistdist/dnsdist.service.in [new file with mode: 0644]
pdns/dnsdistdist/m4/systemd.m4

index 15a59766c84606dcd174eb80f8ab93c2a9222757..11b6c494ff2b74d7151d033ea8a05e7f8ef22a11 100755 (executable)
@@ -40,8 +40,10 @@ SODIUM_CONFIGURE=''
 
 # Some RPM platforms use systemd, others sysv, we default to systemd here
 INIT_BUILDREQUIRES='BuildRequires: systemd'
-INIT_INSTALL='install -d -m 755 %{buildroot}/%{_sysconfdir}/systemd/system/ && install -m 664 contrib/dnsdist.service %{buildroot}/%{_sysconfdir}/systemd/system/dnsdist.service'
-INIT_FILES='%{_sysconfdir}/systemd/system/dnsdist.service'
+#INIT_INSTALL='install -d -m 755 %{buildroot}/lib/systemd/system/ && install -m 664 dnsdist.service %{buildroot}/lib/systemd/system/dnsdist.service'
+INIT_INSTALL=''
+INIT_FILES='/lib/systemd/system/dnsdist.service'
+INIT_CONFIGURE='--enable-systemd --with-systemd=/lib/systemd/system \'
 
 # These two are the same for sysv and systemd (we don't install defaults files at the moment)
 DEFAULTS_INSTALL=''
@@ -64,6 +66,7 @@ if [ -f /etc/redhat-release ]; then
       INIT_BUILDREQUIRES=''
       INIT_INSTALL='install -d -m 755 %{buildroot}/%{_initrddir} && install -m 755 contrib/dnsdist.init.centos6 %{buildroot}/%{_initrddir}/dnsdist'
       INIT_FILES='%{_initrddir}/dnsdist'
+      INIT_CONFIGURE='\'
       SETUP="%setup -n %{name}-${TARBALLVERSION}"
       RPMBUILD_COMMAND="scl enable devtoolset-3 -- ${RPMBUILD_COMMAND}"
       ;;
@@ -101,6 +104,7 @@ ${SETUP}
 %build
 %configure \
   --sysconfdir=/etc/dnsdist \
+  ${INIT_CONFIGURE}
   ${SODIUM_CONFIGURE}
 
 make
index 7eff7391c3d235d51cec90498fb7aa158c0eeaaa..6b11f4ec3b85680c7a79223655d88d97a6a4e4be 100644 (file)
@@ -3,7 +3,7 @@ Section: net
 Priority: optional
 Maintainer: PowerDNS Autobuilder <powerdns.support@powerdns.com>
 Origin: PowerDNS
-Build-Depends: debhelper (>= 9), dh-autoreconf, dh-systemd (>= 1.5), libboost-dev, libedit-dev, liblua5.2-dev, pkg-config @LIBSODIUMDEV@
+Build-Depends: debhelper (>= 9), dh-autoreconf, dh-systemd (>= 1.5), libboost-dev, libedit-dev, liblua5.2-dev, pkg-config @LIBSODIUMDEV@ @LIBSYSTEMDDEV@
 Standards-Version: 3.9.7
 Homepage: http://dnsdist.org
 
index 13d72806035695c8dea5911e3cafdc388a76dd4f..8a265b4b15fe9d5b788c7bbee72bdd35dcddbf80 100644 (file)
@@ -4,8 +4,10 @@ Wants=network-online.target
 After=network-online.target
 
 [Service]
-# Keep the --supervised and --disable-syslog option when modifying the default options
+# Note: when editing the ExecStart command, keep --supervised and --disable-syslog
 ExecStart=/usr/bin/dnsdist --supervised --disable-syslog -u _dnsdist -g _dnsdist
+
+Type=notify
 Restart=on-failure
 RestartSec=2
 TimeoutStopSec=5
index 3c8f11ce344ad155d63b3512507b1765fee4677d..7bfaa48207423bbcb7fddb67d866169f5ad12888 100755 (executable)
@@ -9,6 +9,9 @@ include /usr/share/dpkg/default.mk
 
 ENABLE_LIBSODIUM := --enable-libsodium
 LIBSODIUM_DEV := , libsodium-dev
+
+ENABLE_SYSTEMD := --enable-systemd --with-systemd=/lib/systemd/system
+LIBSYSTEMD_DEV := , libsystemd-dev
 DEBHELPER_WITH_SYSTEMD := --with systemd
 
 # $(ID) and $(VERSION_ID) come from the environment, source this from /etc/os-release
@@ -16,13 +19,16 @@ ifeq ($(ID), ubuntu)
   ifeq ($(VERSION_ID), 14.04)
     # Disable building and depending on libsodium on Ubuntu Trusty
     ENABLE_LIBSODIUM=
+    ENABLE_SYSTEMD=
+    LIBSYSTEMD_DEV=
     LIBSODIUM_DEV=
     DEBHELPER_WITH_SYSTEMD=
   endif
 endif
 
 debian/control: debian/control.in
-       sed -E "s!@LIBSODIUMDEV@!$(LIBSODIUM_DEV)!" $< > $@
+       sed -e "s!@LIBSODIUMDEV@!$(LIBSODIUM_DEV)!" \
+           -e "s!@LIBSYSTEMDDEV@!$(LIBSYSTEMD_DEV)!" $< > $@
 
 %:
        dh $@ \
@@ -40,6 +46,7 @@ override_dh_auto_configure:
          --infodir=\$${prefix}/share/info \
          --libdir='$${prefix}/lib/$(DEB_HOST_MULTIARCH)' \
          --libexecdir='$${prefix}/lib' \
+         $(ENABLE_SYSTEMD) \
          $(ENABLE_LIBSODIUM)
 
 override_dh_auto_build-arch:
index 624b42f8c933922007c7211e3b1911566df77e24..90c64d05a4b2d73557e45628c3c02726c1ee72b2 100644 (file)
@@ -14,6 +14,10 @@ Compiling
 compiler (g++ 4.8 or higher, clang 3.5 or higher). It can optionally use libsodium
 for encrypted communications with its client.
 
+Should `dnsdist` be run on a system with systemd, it is highly recommended to have
+the systemd header files (`libsystemd-dev` on debian and `systemd-devel` on CentOS)
+installed to have `dnsdist` support systemd-notify.
+
 To compile on CentOS 6 / RHEL6, use this script to install a working compiler:
 
 ```
index 0ab42a439a8605af1c1978555c4e98078c8a1fa6..42aaab46914ccc789f9cb4572402de0af29b3868 100644 (file)
@@ -9,6 +9,10 @@
 #include "lock.hh"
 #include <net/if.h>
 
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
+
 using std::thread;
 
 static vector<std::function<void(void)>>* g_launchWork;
@@ -497,7 +501,12 @@ vector<std::function<void(void)>> setupLua(bool client, const std::string& confi
         g_outputBuffer+=s+"\n";
 
     });
-  g_lua.writeFunction("shutdown", []() { _exit(0);} );
+  g_lua.writeFunction("shutdown", []() {
+#ifdef HAVE_SYSTEMD
+      sd_notify(0, "STOPPING=1");
+#endif
+      _exit(0);
+  } );
 
 
   g_lua.writeFunction("addDomainBlock", [](const std::string& domain) { 
index d658cb630dc9038d2ab3f406f7884222f789d576..c301c7fa0b7e303501eb296d79d641daa0bac68b 100644 (file)
 #include <getopt.h>
 #include "dnsdist-cache.hh"
 
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
+
 /* Known sins:
 
    Receiver is currently single threaded
@@ -1475,6 +1479,7 @@ try
       break;
     }
   }
+
   argc-=optind;
   argv+=optind;
   for(auto p = argv; *p; ++p) {
@@ -1724,6 +1729,9 @@ try
   thread healththread(healthChecksThread);
 
   if(g_cmdLine.beDaemon || g_cmdLine.beSupervised) {
+#ifdef HAVE_SYSTEMD
+    sd_notify(0, "READY=1");
+#endif
     healththread.join();
   }
   else {
index 7c3177d2c55dd7a023f01500d11e80b21f603d6f..6a62959c6ee9fdd2b633e9b6e5d618e6aac38cfd 100644 (file)
@@ -31,3 +31,4 @@
 /dnsdist
 /dnsmessage.pb.cc
 /dnsmessage.pb.h
+/dnsdist.service
index 3af60a85adfd03b83748d00c83d5184099ec0c33..9d96068f38099e4e34563f2152a31e157a191bbf 100644 (file)
@@ -1,4 +1,4 @@
-AM_CPPFLAGS += $(LUA_CFLAGS) $(LIBEDIT_CFLAGS) $(YAHTTP_CFLAGS) $(SANITIZER_FLAGS) -DSYSCONFDIR=\"${sysconfdir}\"
+AM_CPPFLAGS += $(SYSTEMD_CFLAGS) $(LUA_CFLAGS) $(LIBEDIT_CFLAGS) $(YAHTTP_CFLAGS) $(SANITIZER_FLAGS) -DSYSCONFDIR=\"${sysconfdir}\"
 
 ACLOCAL_AMFLAGS = -I m4
 
@@ -39,7 +39,8 @@ EXTRA_DIST=dnslabeltext.rl \
           build-aux/gen-version \
           ext/incbin/UNLICENSE \
           incfiles \
-          src_js
+          src_js \
+          dnsdist.service.in
 
 bin_PROGRAMS = dnsdist
 
@@ -100,7 +101,8 @@ dnsdist_LDADD = \
        $(RT_LIBS) \
        $(YAHTTP_LIBS) \
        $(LIBSODIUM_LIBS) \
-       $(SANITIZER_FLAGS)
+       $(SANITIZER_FLAGS) \
+       $(SYSTEMD_LIBS)
 
 if HAVE_RE2
 dnsdist_LDADD += $(RE2_LIBS)
@@ -178,3 +180,13 @@ $(MANPAGES):
        exit 1
 endif
 endif
+
+if HAVE_SYSTEMD
+dnsdist.service: dnsdist.service.in
+       $(AM_V_GEN)sed -e 's![@]bindir[@]!$(bindir)!' < $< > $@
+
+systemdsystemunitdir = $(SYSTEMD_DIR)
+
+systemdsystemunit_DATA = \
+       dnsdist.service
+endif
index ed896fb43228752d7e0e683b4743ffdd1efa6f28..1f5d0c89fd464eba19625356dbba53b58f8bd784 100644 (file)
@@ -19,6 +19,9 @@ PDNS_CHECK_RE2
 DNSDIST_ENABLE_DNSCRYPT
 PDNS_WITH_PROTOBUF
 
+AX_AVAILABLE_SYSTEMD
+AM_CONDITIONAL([HAVE_SYSTEMD], [ test x"$systemd" = "xy" ])
+
 AC_SUBST([YAHTTP_CFLAGS], ['-I$(top_srcdir)/ext/yahttp'])
 AC_SUBST([YAHTTP_LIBS], ['$(top_builddir)/ext/yahttp/yahttp/libyahttp.la'])
 
index 11067dfc8a692fcad057d49dcbf208c8629a37f1..43bc1d58c127f359ed3d587252ade36a86f2285c 100644 (file)
@@ -3,7 +3,7 @@ Description=dnsdist
 After=network.target
 
 [Service]
-# Keep the --supervised option when changing the default options
+Type=notify
 ExecStart=/usr/bin/dnsdist --supervised
 
 [Install]
diff --git a/pdns/dnsdistdist/dnsdist.service.in b/pdns/dnsdistdist/dnsdist.service.in
new file mode 100644 (file)
index 0000000..e028c17
--- /dev/null
@@ -0,0 +1,24 @@
+[Unit]
+Description=DNS Loadbalancer
+Wants=network-online.target
+After=network-online.target
+
+[Service]
+# Note: when editing the ExecStart command, keep --supervised and --disable-syslog
+ExecStart=@bindir@/dnsdist --supervised --disable-syslog
+
+Type=notify
+Restart=on-failure
+RestartSec=2
+TimeoutStopSec=5
+StartLimitInterval=0
+PrivateTmp=true
+PrivateDevices=true
+CapabilityBoundingSet=CAP_NET_BIND_SERVICE CAP_SETGID CAP_SETUID
+NoNewPrivileges=true
+ProtectSystem=full
+ProtectHome=true
+RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
+
+[Install]
+WantedBy=multi-user.target
index 182a56ae3cfba880adccfa5faeefc711612d851d..0256f473c9412e80c440d94ec73baac84d4cbfec 100644 (file)
@@ -1,6 +1,7 @@
 # systemd.m4 - Macros to check for and enable systemd          -*- Autoconf -*-
 #
 # Copyright (C) 2014 Luis R. Rodriguez <mcgrof@suse.com>
+# Copyright (C) 2016 Pieter Lexis <pieter.lexis@powerdns.com>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -16,6 +17,8 @@
 # along with this program; if not, write to the Free Software Foundation, Inc.,
 # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
+#serial 2
+
 dnl Some optional path options
 AC_DEFUN([AX_SYSTEMD_OPTIONS], [
        AC_ARG_WITH(systemd, [  --with-systemd          set directory for systemd service files],
@@ -39,13 +42,13 @@ AC_DEFUN([AX_ALLOW_SYSTEMD_OPTS], [
 
 AC_DEFUN([AX_CHECK_SYSTEMD_LIBS], [
        AC_CHECK_HEADER([systemd/sd-daemon.h], [
-           AC_CHECK_LIB([systemd-daemon], [sd_listen_fds], [libsystemddaemon="y"])
+           AC_CHECK_LIB([systemd], [sd_listen_fds], [libsystemd="y"])
        ])
-       AS_IF([test "x$libsystemddaemon" = x], [
-           AC_MSG_ERROR([Unable to find a suitable libsystemd-daemon library])
+       AS_IF([test "x$libsystemd" = x], [
+           AC_MSG_ERROR([Unable to find a suitable libsystemd library])
        ])
 
-       PKG_CHECK_MODULES([SYSTEMD], [libsystemd-daemon])
+       PKG_CHECK_MODULES([SYSTEMD], [libsystemd])
        dnl pkg-config older than 0.24 does not set these for
        dnl PKG_CHECK_MODULES() worth also noting is that as of version 208
        dnl of systemd pkg-config --cflags currently yields no extra flags yet.
@@ -95,7 +98,7 @@ AC_DEFUN([AX_CHECK_SYSTEMD], [
 
 AC_DEFUN([AX_CHECK_SYSTEMD_ENABLE_AVAILABLE], [
        AC_CHECK_HEADER([systemd/sd-daemon.h], [
-           AC_CHECK_LIB([systemd-daemon], [sd_listen_fds], [systemd="y"])
+           AC_CHECK_LIB([systemd], [sd_listen_fds], [systemd="y"])
        ])
 ])