From owner-freebsd-current Wed Oct 25 13:17:50 2000 Delivered-To: freebsd-current@freebsd.org Received: from guru.mired.org (okc-27-149-77.mmcable.com [24.27.149.77]) by hub.freebsd.org (Postfix) with SMTP id 1FD3A37B4C5 for ; Wed, 25 Oct 2000 13:17:47 -0700 (PDT) Received: (qmail 95559 invoked by uid 100); 25 Oct 2000 20:17:46 -0000 From: Mike Meyer MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <14839.16362.106387.571284@guru.mired.org> Date: Wed, 25 Oct 2000 15:17:46 -0500 (CDT) To: Gerhard Sittig Cc: freebsd-current@FreeBSD.ORG Subject: Re: new rc.network6 and rc.firewall6 In-Reply-To: <20001025201401.Q25237@speedy.gsinet> References: <21367.972424567@winston.osd.bsdi.com> <20001025201401.Q25237@speedy.gsinet> X-Mailer: VM 6.75 under 21.1 (patch 10) "Capitol Reef" XEmacs Lucid X-face: "5Mnwy%?j>IIV\)A=):rjWL~NB2aH[}Yq8Z=u~vJ`"(,&SiLvbbz2W`;h9L,Yg`+vb1>RG% *h+%X^n0EZd>TM8_IB;a8F?(Fb"lw'IgCoyM.[Lg#r\ Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Gerhard Sittig writes: > What's new is: > - include the general config at the start (and yes, in every > single script -- but this should be neglectable in terms of > speed penalty and makes them work separately, too -- which is a > real big gain!) This isn't really new; it's been nagging me for a while. Also, periodic.conf does this now. I'm not convined it's negligible when added up over dozens of scripts. I'm planning on taking some measurements to see how much this really costs. I believe I have a solution if it turns out to be non-negligible. > - maybe include (source) some common code like > - determining pids belonging to program names > - starting processes in an supervised or backgrounded or any > other special way > - have some printouts, error level summary, etc > but I don't see FreeBSD having this level of "rc lib" as NetBSD > has in rc.subr or even RedHat has in /etc/rc.d/functions(sp?). > So only the sourced rc.conf (default and customized) remains. Said solutions works shell functions as well. > The real new part eating most of the time to implement is the > shutdown path (which I understand to be somewhat absent in > FreeBSD right now, "kill -TERM everything" seems to do the job > right now). Well, rc.shutdown has the appropriate loop processing in it for doing this for the rc.d directories already. So the new part is the per-system shutdown. That's where the shell subroutine library comes in handy. Provide functions start/stop/reconfig that do the right thing for the conventional single daemon subsystem like so (vertically compressed to save space): start() { eval command="\$${name}_program \$${name}_flags" command & echo $! > /var/run/${name}.pid echo -n " $name" } stop() { kill -TERM /var/run/${name}.pid echo -n " $name" } config() { kill -HUP /var/run/${name}.pid } run() eval check="\$${name}_enable" case "${check}" in [Yy][Ee][Ss]) run="yes" ;; [Nn][Oo]) run="no" ;; esac case "$1" in start) if [ "$run" = "yes" ]; then start(); fi ;; stop) if [ "$run" = "yes" ]; then stop(); fi ;; config) if [ "$run" = "yes" ]; then config(); fi ;; *) echo "Usage: $0 [ start | stop | config ] $1>2 ;; esac } Then simple daemons turn into: #!/bin/sh # # PROVIDES: foobar # REQUIRES: ... # ... name=foobar . /etc/rc.setup run Breaking out the seperate functions allows you to change just part of it easily. For example, if the daemon creates a pid, or the flags to it, you'd do: #!/bin/sh # ... name=smartbar . /etc/rc.setup start() { $foobar_program $foobar_flags & echo -n " foobar" } run Some things are hairy enough to require doing everything over, and there is probably a better way to organize the subroutines, but that's the general idea. The next step is to get ports authors to start using /etc/rc.setup or whatever it gets called :-).