From fb4333612b833ee32e11ac83aac75c460fe55ff3 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Tue, 13 Dec 2016 11:11:25 +0100 Subject: [PATCH] dnsdist: check config before starting --- pdns/dnsdistdist/contrib/dnsdist.init.centos6 | 19 +++++++++++++++++-- pdns/dnsdistdist/dnsdist.service.in | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/pdns/dnsdistdist/contrib/dnsdist.init.centos6 b/pdns/dnsdistdist/contrib/dnsdist.init.centos6 index ebd8ce0218..33b4f903c1 100644 --- a/pdns/dnsdistdist/contrib/dnsdist.init.centos6 +++ b/pdns/dnsdistdist/contrib/dnsdist.init.centos6 @@ -31,8 +31,20 @@ fi RETVAL=0 +do_check() { + msg=$(${DNSDIST} ${DNSDIST_OPTIONS} --check-config 2>&1) + if [ $? -ne 0 ]; then + echo "Error in configuration file:" >&2 + echo "${msg}" >&2 + return 1 + fi +} + do_start() { echo -n "Starting ${PROG}..." + if [ do_check -ne 0 ]; then + return 1 + fi daemon --pidfile=${PIDFILE} $DNSDIST -u ${DNSDIST_USER} -g ${DNSDIST_GROUP} -d -p ${PIDFILE} ${DNSDIST_OPTIONS} ret=$? echo @@ -63,12 +75,15 @@ case "$1" in do_status >/dev/null 2>&1 ret=$? - if [ $? -eq 0 ]; then + if [ ${ret} -eq 0 ]; then + if [ do_check -ne 0 ]; then + exit 1 # Don't stop when there's an error + fi do_stop - ret=$? fi do_start + RETVAL=$? ;; status) do_status diff --git a/pdns/dnsdistdist/dnsdist.service.in b/pdns/dnsdistdist/dnsdist.service.in index 543bfcea81..c7e1b4246a 100644 --- a/pdns/dnsdistdist/dnsdist.service.in +++ b/pdns/dnsdistdist/dnsdist.service.in @@ -6,6 +6,7 @@ Wants=network-online.target After=network-online.target [Service] +ExecStartPre=@bindir@/dnsdist --check-config # Note: when editing the ExecStart command, keep --supervised and --disable-syslog ExecStart=@bindir@/dnsdist --supervised --disable-syslog -- 2.47.2