From owner-freebsd-current@FreeBSD.ORG Fri Oct 17 03:41:39 2014 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 41A55BC0; Fri, 17 Oct 2014 03:41:39 +0000 (UTC) Received: from mx1.scaleengine.net (beauharnois2.bhs1.scaleengine.net [142.4.218.15]) by mx1.freebsd.org (Postfix) with ESMTP id 1AE12AE8; Fri, 17 Oct 2014 03:41:38 +0000 (UTC) Received: from [192.168.1.2] (Seawolf.HML3.ScaleEngine.net [209.51.186.28]) (Authenticated sender: allanjude.freebsd@scaleengine.com) by mx1.scaleengine.net (Postfix) with ESMTPSA id B186160706; Fri, 17 Oct 2014 03:41:31 +0000 (UTC) Message-ID: <54408FF3.10902@freebsd.org> Date: Thu, 16 Oct 2014 23:41:39 -0400 From: Allan Jude User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 MIME-Version: 1.0 To: freebsd-current@freebsd.org Subject: Re: [CFT] multiple instance support in rc.d script References: <20141017.102259.2303779237508789020.hrs@allbsd.org> In-Reply-To: <20141017.102259.2303779237508789020.hrs@allbsd.org> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="KjqH1SK7gMFcjvNrbxSvMMsqEkCcmPP1J" Cc: "dte >> Devin Teske" X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Oct 2014 03:41:39 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --KjqH1SK7gMFcjvNrbxSvMMsqEkCcmPP1J Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On 2014-10-16 21:22, Hiroki Sato wrote: > [Please reply to freebsd-rc@] >=20 > Hi, >=20 > I would like your feedback and testers of the attached patch. This > implements multiple instance support in rc.d scripts. You can try it > by replacing /etc/rc.subr with the attached one. >=20 > More details are as follow. Typically, an rc.d/foo script has the > following structure and rc.conf variables: >=20 > /etc/rc.d/foo: > ---- > name=3Dfoo > rcvar=3Dfoo_enable > ... > load_rc_command $name > run_rc_command $* > ---- >=20 > /etc/rc.conf: > ---- > foo_enable=3D"YES" > foo_flags=3D"-f -l -a -g" > ---- >=20 > The above supports one instance for one script. After replacing > rc.subr, you can specify additional instances in rc.conf: >=20 > /etc/rc.conf: > ---- > foo_instances=3D"one two" >=20 > foo_one_enable=3D"YES" > foo_one_flags=3D"-f -l -a -g" >=20 > foo_two_enable=3D"YES" > foo_two_flags=3D"-F -L -A -G" > ---- >=20 > $foo_instances defines instances by space-separated list of instance > names, and rc.conf variables for them are something like > ${name}_${instname}_enable. The following command >=20 > # service foo start >=20 > starts foo_one and foo_two with the specified flags. Instances can > be specified in the following form: >=20 > # service foo start:one >=20 > or multiple instances in a particular order: >=20 > # service foo start:two,one >=20 > Basically, no change is required for the rc.d/foo script itself. > However, there is a problem that default values of the instantiated > variables are not defined. >=20 > For example, if an rc.d/script uses $foo_mode, you need to define > $foo_one_mode. The default value of $foo_mode is usually defined in > etc/defaults/rc.conf for rc.d scripts in the base system and ": > ${foo_mode:=3Dvalue}" idiom in scripts from Ports Collection. So all > of the variables should be defined for each instance, too. As you > noticed, this is not easy without editing the script itself. >=20 > To alleviate this, set_rcvar() can be used: >=20 > /etc/rc.d/foo: > ---- > name=3Dfoo > rcvar=3Dfoo_enable >=20 > set_rcvar foo_enable YES "Enable $name" > set_rcvar foo_program "/tmp/test" "Command for $name" > ... > load_rc_command $name > run_rc_command $* > ---- >=20 > The three arguments are varname, default value, and description. If > a variable is defined by set_rcvar(), default values instantiated > variables will be set automatically---foo_one_program is set by > foo_program if it is not defined. >=20 > This approach still has another problem. set_rcvar() is not > supported in all branches, so a script using it does not work in old > supported branches. One solution which can be used for scripts in > Ports Collection is adding both definitions before and after > load_rc_command() until EoL of old branches like this: >=20 > /etc/rc.d/foo: > ---- > name=3Dfoo > rcvar=3Dfoo_enable >=20 > if type set_rcvar >/dev/null 2>&1; then > set_rcvar foo_enable YES "Enable $name" > set_rcvar foo_program "/tmp/test" "Command for $name" > fi > ... > load_rc_command $name >=20 > # will be removed after all supported branches have set_rcvar(). > if ! type set_rcvar >/dev/null 2>&1; then > : ${foo_enable:=3D"YES"} > : ${foo_program:=3D"/tmp/test"} > for _i in $foo_instances; do > for _j in enable program; do > eval : \${foo_${_i}_enable:=3D\$foo_$_j} > done > done > fi >=20 > run_rc_command $* > ---- >=20 > This is a bit ugly but should work fine. >=20 > I am using this patch to invoke multiple named (caching > server/contents server) and syslogd (local only/listens INET/INET6 > socket only) daemons. While $foo_instances is designed as a > user-defined knob, this can be applied to software which need to > invoke multiple/different daemons which depend on each other in a > script, too. >=20 > I am feeling this patch still needs more careful review from others. > Any comments are welcome. Thank you. >=20 > -- Hiroki >=20 This feature is quite useful. I've used the built in version that the rc.d script in memcached and it is very helpful to be able to run multiple named instances. I wonder if sysrc could be improved to support an 'append', so you can ha= ve: foo_instances=3D"one two" and do: sysrc --append foo_instances=3Dthree to get: foo_instances=3D"one two three" instead of having to do: sysrc foo_instances=3D"`sysrc -n foo_instances` three" or something more convoluted --=20 Allan Jude --KjqH1SK7gMFcjvNrbxSvMMsqEkCcmPP1J 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.0.22 (MingW32) iQIcBAEBAgAGBQJUQI/2AAoJEJrBFpNRJZKf82wP/1j1bAHgJqk4moMCI6fLgK4y yATrAPOY7NcX7TIqI719JvhLTrgxzUrdTVAY9O/TYuOtlVz0FabtvPbL2Pd8yS+f z94IKkiF3dNglXz0DeFNBoi3bIstAL6eP9Rxrbx5zFxDOCLQjqZBWTIhjElPSrUF JsiWcsHGcbtG8aD9YKI4zXlK8WrKtWISBGikZ3B2jEuT5yw+mIkCKspmHMac+DfY Y1/wdxECjuLkvhNHgJCvR6pZLDEyu3O8bzRxfKpI/68T131S/4SEDZeNUN69NFYG 927v5ZqOX0AYIFZPw05NpEmFjUUz9/f1GJTYnyHfpP7ZaXF5o8FbUFXS/zAzFFgs VH/I/ws45xfsrKNDH1JXfxPQJczAvFxnR6LIaqiOKAqm1lvM5HKDqplftWlA5uox /CzY6njDiugYGaOY2yJhx2Qj6g0PNUUECjDPeZqw6dCHQohltiYK81LaNG6vOLJK 12vizOcqYIb+eQm9UI8vBqY9wFwWuDJNu963YtkNiVDc74Z2k/1w2qhtHzrHkMvW SYO1BTo+OZApo2Nvh/U3qyd9huOmaBa3YL8aUCOHruE8zqbmkEzgWKj67gQM9Nk9 OowYx8y8+36jij7QkJiDqP2Rm5Y6nFsVWn2Y94PJGXMS3tZ2fckZp8f178+fwLQs TfDfGRs7IK65f3VfITbz =VlVl -----END PGP SIGNATURE----- --KjqH1SK7gMFcjvNrbxSvMMsqEkCcmPP1J--