Howdy,I'm currently working on a project that requires multiple instances of named to run on the same server. So I took some time to modify the rc.d 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 here. However that original mechanism was not ever/widely used. As a result some of the code was removed, some of it rotted, etc. It's still *relatively* easy to do, and hopefully the notes included in the patch explain the process sufficiently.
FWIW, I don't care if the patch is incorporated anywhere or not. But since the work is already done I thought I'd share it in case it's useful to someone.
best regards, Doug
--- /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 @@
. /etc/rc.subr
-name="named"
-rcvar=named_enable
+name="${0##*/}"
+rcvar="${name}_enable"
extra_commands="reload"
@@ -100,7 +100,7 @@
make_symlinks
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 @@
named_reload()
{
- ${command%/named}/rndc reload
+ ${command%/*}/${rndc} reload
}
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 @@
# Create an rndc.key file for the user if none exists
#
- confgen_command="${command%/named}/rndc-confgen -a -b256 -u $named_uid \
+ confgen_command="${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 @@
local checkconf
- checkconf="${command%/named}/named-checkconf"
+ checkconf="${command%/*}/named-checkconf"
if ! checkyesno named_chroot_autoupdate && [ -n "$named_chrootdir" ]; then
checkconf="$checkconf -t $named_chrootdir"
fi
@@ -292,10 +292,39 @@
load_rc_config $name
+# These changes, and the changes to name and rcvar, are necessary to allow
+# multiple instances of the same service. In order to avoid tripping the
+# "foo already running?" test it is also necessary to create a symlink to the
+# binary, and use that symlink name as foo_program. For BIND particularly you
+# will also need to use a rndc.conf file and controls {}; clause in named.conf.
+#
+# It is necessary to update these variables here instead of ad hoc in the script
+# because you cannot do pattern substitution and variable substitution in 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="\$${name}_enable"
+eval named_program="\$${name}_program"
+eval named_conf="\$${name}_conf"
+eval named_flags="\$${name}_flags"
+eval named_uid="\$${name}_uid"
+eval named_chrootdir="\$${name}_chrootdir"
+eval named_chroot_autoupdate="\$${name}_chroot_autoupdate"
+eval named_symlink_enable="\$${name}_symlink_enable"
+eval named_wait="\$${name}_wait"
+eval named_wait_host="\$${name}_wait_host"
+eval named_auto_forward="\$${name}_auto_forward"
+eval named_auto_forward_only="\$${name}_auto_forward_only"
+
# Updating the following variables requires that rc.conf be loaded first
#
required_dirs="$named_chrootdir" # if it is set, it must exist
named_confdir="${named_chrootdir}${named_conf%/*}"
+rndc=rndc
+[ -s "${named_confdir}/rndc.conf" ] && rndc="${rndc} -c ${named_confdir}/rndc.conf"
+
run_rc_command "$1"
signature.asc
Description: OpenPGP digital signature
