Subject: Re: Updating /etc...
To: None <jonathan@dsg.stanford.edu>
From: Niklas Hallqvist <niklas@appli.se>
List: current-users
Date: 12/20/1995 17:57:37
I thought I'd toss in yet another idea (or rather an experimental
implementation of some idea I've seen suring the course of this
discussion).
How about this, two dirs, one for executables, and one for config
info. The files in these dirs are named as the packages.
$bin keeps the start/stop/reconfig binaries/scripts
$conf holds a configuration script containing *one*
comment matching the RE:
^#[ +t]*require[ \t](.*)
where the parenthesis part should hold other pkg-names
this package depends upon
$bin could be /sbin, /sbin/init.d, /etc/init.d, /etc/sysconf whatever
$conf could be /etc/pkg or whatever
Now I put together this scipt, I call pkg-run, that takes an argument
"start" or "stop". It'll parse the require lines and make a partial
order and run the package's scripts in either forward or reverse order
depending on if we start or stop. It will also source the config
script before running the package's scripts. This way a config file
might look like:
# require nfs dns
LIBDIR=/usr/local/lib/foo; export LIBDIR
So what do you think? This is just the base of discussion of course.
Things that could be added are to not start/stop already
started/stopped packages. To not start dependant packages if failure
occurs, likewise for stop, etc. It's just a five-minute script so
don't be too hard on me :-)
Niklas
#!/bin/sh
# pkg-run
conf=/tmp/pkg
bin=/tmp/sbin
usage ()
{
echo "usage: $0 [start|stop]" >&2
exit 1
}
if [ $# != 1 ]; then
usage
fi
cmd=$1
case $cmd in
start)
reverse=no
;;
stop)
reverse=yes
;;
*)
usage
;;
esac
cd $conf
for pkg in *; do
require=`sed -n 's/^#[ ]*require[ ]//p' $pkg`
if [ "X$require" = X ]; then
echo $pkg $pkg
else
for req in $require; do
if [ X$reverse = Xyes ]; then
echo $pkg $req
else
echo $req $pkg
fi
done
fi
done |tsort |while read pkg; do
(. $conf/$pkg; $bin/$pkg $cmd)
done