# 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=''
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}"
;;
%build
%configure \
--sysconfdir=/etc/dnsdist \
+ ${INIT_CONFIGURE}
${SODIUM_CONFIGURE}
make
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
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
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
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 $@ \
--infodir=\$${prefix}/share/info \
--libdir='$${prefix}/lib/$(DEB_HOST_MULTIARCH)' \
--libexecdir='$${prefix}/lib' \
+ $(ENABLE_SYSTEMD) \
$(ENABLE_LIBSODIUM)
override_dh_auto_build-arch:
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:
```
#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;
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) {
#include <getopt.h>
#include "dnsdist-cache.hh"
+#ifdef HAVE_SYSTEMD
+#include <systemd/sd-daemon.h>
+#endif
+
/* Known sins:
Receiver is currently single threaded
break;
}
}
+
argc-=optind;
argv+=optind;
for(auto p = argv; *p; ++p) {
thread healththread(healthChecksThread);
if(g_cmdLine.beDaemon || g_cmdLine.beSupervised) {
+#ifdef HAVE_SYSTEMD
+ sd_notify(0, "READY=1");
+#endif
healththread.join();
}
else {
/dnsdist
/dnsmessage.pb.cc
/dnsmessage.pb.h
+/dnsdist.service
-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
build-aux/gen-version \
ext/incbin/UNLICENSE \
incfiles \
- src_js
+ src_js \
+ dnsdist.service.in
bin_PROGRAMS = dnsdist
$(RT_LIBS) \
$(YAHTTP_LIBS) \
$(LIBSODIUM_LIBS) \
- $(SANITIZER_FLAGS)
+ $(SANITIZER_FLAGS) \
+ $(SYSTEMD_LIBS)
if HAVE_RE2
dnsdist_LDADD += $(RE2_LIBS)
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
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'])
After=network.target
[Service]
-# Keep the --supervised option when changing the default options
+Type=notify
ExecStart=/usr/bin/dnsdist --supervised
[Install]
--- /dev/null
+[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
# 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
# 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],
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.
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"])
])
])