Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Feb 2016 17:57:34 -0800
From:      Doug Barton <dougb@dougbarton.us>
To:        mat@FreeBSD.org
Cc:        freebsd-ports@freebsd.org
Subject:   Patch for named rc.d script to allow multiple instances
Message-ID:  <56CD0E0E.9090907@dougbarton.us>

next in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--NFoicoM7ll0CicmsAhg34ldRN9Ma9fpj3
From: Doug Barton <dougb@dougbarton.us>
To: mat@FreeBSD.org
Cc: freebsd-ports@freebsd.org
Message-ID: <56CD0E0E.9090907@dougbarton.us>
Subject: Patch for named rc.d script to allow multiple instances
Content-Type: multipart/mixed;
 boundary="------------020308070605010900080209"

--------------020308070605010900080209
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Howdy,

I'm currently working on a project that requires multiple instances of=20
named to run on the same server. So I took some time to modify the rc.d=20
script to support that robustly.

The original concept for rc.d was that it should be easy to run multiple =

instances of the same service, using a mechanism similar to the one=20
here. However that original mechanism was not ever/widely used. As a=20
result some of the code was removed, some of it rotted, etc. It's still=20
*relatively* easy to do, and hopefully the notes included in the patch=20
explain the process sufficiently.

FWIW, I don't care if the patch is incorporated anywhere or not. But=20
since the work is already done I thought I'd share it in case it's=20
useful to someone.

best regards,

Doug

--------------020308070605010900080209
Content-Type: text/x-patch;
 name="named-rcd.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
 filename="named-rcd.diff"

--- /etc/rc.d/named-orig	2014-10-22 21:25:01.000000000 +0000
+++ named_rec	2016-02-24 00:55:16.000000000 +0000
@@ -9,8 +9,8 @@
=20
 . /etc/rc.subr
=20
-name=3D"named"
-rcvar=3Dnamed_enable
+name=3D"${0##*/}"
+rcvar=3D"${name}_enable"
=20
 extra_commands=3D"reload"
=20
@@ -100,7 +100,7 @@
 	make_symlinks
=20
 	if checkyesno named_wait; then
-		until ${command%/sbin/named}/bin/host $named_wait_host >/dev/null 2>&1=
; do
+		until ${command%/sbin/*}/bin/host $named_wait_host >/dev/null 2>&1; do=

 			echo "	Waiting for nameserver to resolve $named_wait_host"
 			sleep 1
 		done
@@ -109,7 +109,7 @@
=20
 named_reload()
 {
-	${command%/named}/rndc reload
+	${command%/*}/${rndc} reload
 }
=20
 find_pidfile()
@@ -135,7 +135,7 @@
 		return 1
 	fi
 	echo 'Stopping named.'
-	if ${command%/named}/rndc stop 2>/dev/null; then
+	if ${command%/*}/${rndc} stop 2>/dev/null; then
 		wait_for_pids $rc_pid
 	else
 		echo -n 'rndc failed, trying kill: '
@@ -195,7 +195,7 @@
=20
 	# Create an rndc.key file for the user if none exists
 	#
-	confgen_command=3D"${command%/named}/rndc-confgen -a -b256 -u $named_ui=
d \
+	confgen_command=3D"${command%/*}/rndc-confgen -a -b256 -u $named_uid \
 	    -c ${named_confdir}/rndc.key"
 	if [ -s "${named_confdir}/rndc.conf" ]; then
 		unset confgen_command
@@ -211,7 +211,7 @@
=20
 	local checkconf
=20
-	checkconf=3D"${command%/named}/named-checkconf"
+	checkconf=3D"${command%/*}/named-checkconf"
 	if ! checkyesno named_chroot_autoupdate && [ -n "$named_chrootdir" ]; t=
hen
 		checkconf=3D"$checkconf -t $named_chrootdir"
 	fi
@@ -292,10 +292,39 @@
=20
 load_rc_config $name
=20
+# These changes, and the changes to name and rcvar, are necessary to all=
ow
+# multiple instances of the same service.  In order to avoid tripping th=
e
+# "foo already running?" test it is also necessary to create a symlink t=
o the
+# binary, and use that symlink name as foo_program.  For BIND particular=
ly you
+# will also need to use a rndc.conf file and controls {}; clause in name=
d.conf.
+#
+# It is necessary to update these variables here instead of ad hoc in th=
e script
+# because you cannot do pattern substitution and variable substitution i=
n the same
+# operation (such as ${named_rec_conf%/*} vs. ${${name}_rec_conf%/*}).
+#
+# If new variables are added to the script and/or /etc/defaults/rc.conf =
this
+# list needs to be updated
+#
+eval named_enable=3D"\$${name}_enable"
+eval named_program=3D"\$${name}_program"
+eval named_conf=3D"\$${name}_conf"
+eval named_flags=3D"\$${name}_flags"
+eval named_uid=3D"\$${name}_uid"
+eval named_chrootdir=3D"\$${name}_chrootdir"
+eval named_chroot_autoupdate=3D"\$${name}_chroot_autoupdate"
+eval named_symlink_enable=3D"\$${name}_symlink_enable"
+eval named_wait=3D"\$${name}_wait"
+eval named_wait_host=3D"\$${name}_wait_host"
+eval named_auto_forward=3D"\$${name}_auto_forward"
+eval named_auto_forward_only=3D"\$${name}_auto_forward_only"
+
 # Updating the following variables requires that rc.conf be loaded first=

 #
 required_dirs=3D"$named_chrootdir"	# if it is set, it must exist
=20
 named_confdir=3D"${named_chrootdir}${named_conf%/*}"
=20
+rndc=3Drndc
+[ -s "${named_confdir}/rndc.conf" ] && rndc=3D"${rndc} -c ${named_confdi=
r}/rndc.conf"
+
 run_rc_command "$1"

--------------020308070605010900080209--

--NFoicoM7ll0CicmsAhg34ldRN9Ma9fpj3
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAEBCAAGBQJWzQ4OAAoJEFzGhvEaGryEon4IAKut29MSibiCbLYH1RRuTeaY
YdCRKThtPYZOJ47eMJekSNOxlNn0h+KMv+yJwIyTE3MPtYLjZ+auv+GC+Bj6OpxV
c/xmuRhDSvL+0q8mYc3eedSp5eSU5ikpAzf3wC8Ak/jF58MSDXyeseo0Pg13zHYC
PfFrJNVxRAktzqIkqr2evQvt3TNACMrllB348E6IswnK0LOXJbJiAGR1jVap7xQH
ZoEHy8CtW4q9XwdvCPt0HFdaUL2nO/Cb3wM7MQr+UHud9z32UieT71oH88xYd3uj
OVrBa4tIkpoLEnJbkI1n2jfJcZR30ofxovJ1nPdOQDExUZnNVsiNTwro3p0VdK0=
=Xk0+
-----END PGP SIGNATURE-----

--NFoicoM7ll0CicmsAhg34ldRN9Ma9fpj3--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?56CD0E0E.9090907>