]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: check config before starting 4765/head
authorPieter Lexis <pieter.lexis@powerdns.com>
Tue, 13 Dec 2016 10:11:25 +0000 (11:11 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Tue, 13 Dec 2016 10:11:25 +0000 (11:11 +0100)
pdns/dnsdistdist/contrib/dnsdist.init.centos6
pdns/dnsdistdist/dnsdist.service.in

index ebd8ce0218ee91b2c97b23221e253f97ee88e206..33b4f903c1a3b5efad3a9bc5873c2efc08aed7af 100644 (file)
@@ -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
index 543bfcea814125931443078cfe12aff55d232ae1..c7e1b4246aea45d5d5911cb3fc0749c5a2a16009 100644 (file)
@@ -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