From owner-freebsd-rc@FreeBSD.ORG Wed Nov 7 13:58:48 2007 Return-Path: Delivered-To: freebsd-rc@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 80B3516A41B for ; Wed, 7 Nov 2007 13:58:48 +0000 (UTC) (envelope-from wmoran@collaborativefusion.com) Received: from mx00.pub.collaborativefusion.com (mx00.pub.collaborativefusion.com [206.210.89.199]) by mx1.freebsd.org (Postfix) with ESMTP id 3AB9113C4A8 for ; Wed, 7 Nov 2007 13:58:48 +0000 (UTC) (envelope-from wmoran@collaborativefusion.com) Received: from vanquish.pitbpa0.priv.collaborativefusion.com (vanquish.pitbpa0.priv.collaborativefusion.com [192.168.2.61]) (SSL: TLSv1/SSLv3,256bits,AES256-SHA) by wingspan with esmtp; Wed, 07 Nov 2007 08:48:03 -0500 id 00056407.4731C213.00007A7C Date: Wed, 7 Nov 2007 08:48:03 -0500 From: Bill Moran To: Christopher Cowart Message-Id: <20071107084803.6a3564db.wmoran@collaborativefusion.com> In-Reply-To: <20071107082837.GM65098@hal.rescomp.berkeley.edu> References: <20071107082837.GM65098@hal.rescomp.berkeley.edu> Organization: Collaborative Fusion X-Mailer: Sylpheed 2.4.4 (GTK+ 2.10.14; i386-portbld-freebsd6.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Cc: freebsd-rc@FreeBSD.org Subject: Re: Multiple instances of a daemon X-BeenThere: freebsd-rc@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussion related to /etc/rc.d design and implementation." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Nov 2007 13:58:48 -0000 In response to Christopher Cowart : > Hello, > > I want to be able to use the same rc script to start several instances > of a daemon. When I've encountered this desire before, I've cp'd the > script, given it a unique name, and carried on with my business. This is > a but kludgy and makes updating scripts a manual task. > > Today, I realized the arpd port didn't provide an rc script, so I set > out to write one. I also knew that I was going to be launching several > different arpd's, so I wanted to figure out a better way to deal with > this problem. > > I thought I'd be clever and use symlinks: > rc.d $ ls -l arpd* > -r-xr-xr-x 1 root wheel 486 Nov 7 00:01 arpd > lrwxr-xr-x 1 root wheel 4 Nov 6 23:32 arpd_vlan665 -> arpd > lrwxr-xr-x 1 root wheel 4 Nov 6 23:32 arpd_vlan679 -> arpd > > Then I wrote my rc script with `name=${0##*/}'. Everything was fantastic > doing manual starts and stops. Then I tried rebooting... > > After a few boots, some debugging, and a lot of tracing through /etc/rc > and /etc/rc.subr, I found the problem (or is it a feature?). > run_rc_script() sources the script. All the talk about not sourcing the > "current shell" anymore, and I foolishly assumed that meant something > more like calling the script and less like sourcing it in a subshell. > > I would really find it convenient to use the symlink trick shown above, > because it means a symlink-compatible rc-script can be updated by the > port or mergemaster, and all the "copies" will "just work." I'd be > willing to take the time to implement something, but I don't pretend > to know all the use cases or the motivation behind this design. > > One approach could be that run_rc_script() throws the rc script name > into a variable visible to the sourced script, say _rc_script_name. > Then name could be something like `${_rc_script_name:-${0##*/}}' or a > less terse if/then. > > Is this a feature other people would like to see, or is it just me? The canonical way of doing this has been a "profiles"-enabled rc script. See the Apache or Slony rc scripts for examples. Not sure if your approach might be better. -- Bill Moran Collaborative Fusion Inc. http://people.collaborativefusion.com/~wmoran/ wmoran@collaborativefusion.com Phone: 412-422-3463x4023