From owner-freebsd-ports@freebsd.org Wed Feb 24 01:57:47 2016 Return-Path: Delivered-To: freebsd-ports@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id C34BBAB1AE0 for ; Wed, 24 Feb 2016 01:57:47 +0000 (UTC) (envelope-from dougb@dougbarton.us) Received: from dougbarton.us (dougbarton.us [IPv6:2607:f2f8:ab14::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A0C3E1602; Wed, 24 Feb 2016 01:57:47 +0000 (UTC) (envelope-from dougb@dougbarton.us) Received: from [192.168.0.179] (172-7-206-56.lightspeed.irvnca.sbcglobal.net [172.7.206.56]) by dougbarton.us (Postfix) with ESMTPSA id 17B983A0BD; Wed, 24 Feb 2016 01:57:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dougbarton.us; s=dkim; t=1456279061; bh=RZzayMhHpB1MmtjAUUetavgPFaSBahu2YgbqYXANuic=; h=To:Cc:From:Subject:Date; b=lINXjCBn7dIDk9wEmddvdNk9k7kCmIJjQQHVCVDOwTfNcsiSP7zeFhuLNf+Zx9WYM eBSzBmlOYIozlOT8nldPSHxIB0f1g88xlnRhejj3w0Pm5Dz17i4yh7BjZHhlTtae66 lobeBw+KV5csPhv+NOmKI9bf2rlMxUpzreVkgPGE= To: mat@FreeBSD.org Cc: freebsd-ports@freebsd.org From: Doug Barton Subject: Patch for named rc.d script to allow multiple instances Openpgp: id=E3520E149D053533C33A67DB5CC686F11A1ABC84 Message-ID: <56CD0E0E.9090907@dougbarton.us> Date: Tue, 23 Feb 2016 17:57:34 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.5.1 MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="NFoicoM7ll0CicmsAhg34ldRN9Ma9fpj3" X-Content-Filtered-By: Mailman/MimeDel 2.1.20 X-BeenThere: freebsd-ports@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Porting software to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Feb 2016 01:57:48 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --NFoicoM7ll0CicmsAhg34ldRN9Ma9fpj3 From: Doug Barton 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--