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 :-).
<mike
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message