[OpenWrt-Devel] [PATCH] Add basic instance support to nsd init script

Eric Masson emss at free.fr
Sun Apr 26 08:46:45 EDT 2020


From: Eric Masson <emss at srvbsdfenssv.interne.associated-bears.org>

---
 net/nsd/files/nsd.init | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/net/nsd/files/nsd.init b/net/nsd/files/nsd.init
index 8b1cf1deb..69fdce512 100644
--- a/net/nsd/files/nsd.init
+++ b/net/nsd/files/nsd.init
@@ -5,12 +5,35 @@ START=60
 USE_PROCD=1
 PROG=/usr/sbin/nsd
 
+append_arg() {
+	local cfg="$1"
+	local var="$2"
+	local opt="$3"
+	local def="$4"
+	local val
+
+	config_get val "$cfg" "$var"
+	[ -n "$val" -o -n "$def" ] && procd_append_param command "$opt" "${val:-$def}"
+}
+
+start_instance()
+{
+	local cfg="$1"
+	procd_open_instance
+	procd_set_param respawn
+	procd_set_param stderr 1
+	procd_set_param command "$PROG" -d
+	append_arg "$cfg" config_file "-c"
+	append_arg "$cfg" db_file "-f"
+	append_arg "$cfg" pid_file "-P"
+	procd_close_instance
+}
+
 start_service() {
 	mkdir -p /var/db/nsd
 	chown network /var/db/nsd
 	chmod 640 /etc/nsd/*.conf 2>/dev/null
 	chgrp network /etc/nsd/*.conf 2>/dev/null
-	procd_open_instance
-	procd_set_param command "$PROG" -d
-	procd_close_instance
-}
+	config_load nsd
+	config_foreach start_instance nsd
+}
\ No newline at end of file
-- 
2.26.2


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list