diff mbox series

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

Message ID 20200426124645.7457-1-emss@free.fr
State New
Headers show
Series [OpenWrt-Devel] Add basic instance support to nsd init script | expand

Commit Message

Eric Masson April 26, 2020, 12:46 p.m. UTC
From: Eric Masson <emss@srvbsdfenssv.interne.associated-bears.org>

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

Patch

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