Subject: Re: rc.d and rcorder
To: NetBSD Users's Discussion List <netbsd-users@netbsd.org>
From: Greg A. Woods <woods@planix.com>
List: netbsd-users
Date: 04/23/2007 14:13:58
--pgp-sign-Multipart_Mon_Apr_23_14:13:56_2007-1
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable

At Mon, 23 Apr 2007 17:29:42 +0200, Rhialto wrote:
Subject: Re: rc.d and rcorder
>=20
> On Mon 23 Apr 2007 at 22:55:04 +1000, Malcolm Herbert wrote:
> > how one goes from that to having a foo restart dependancy on bar, I'm
> > not sure ...
>=20
> Other useful activities might be "start up everything up to foo" or
> "start foo everything that it needs", or similar shutdown actions.
> They can probably be done with a little shell scripting and/or small
> extensions to rcorder.

I don't think it's rcorder(8) that needs fixing or changing in any way.

What really needs fixing are all the scripts which do things other than
start daemons.

If all /etc/rc.d scripts were required to do no harm when re-run then it
would be a simple matter to just run all of /etc/rc again manually.

I suppose though if rcorder(8) had a "satisfy" option which would list
just the pre-requisites (but not those given with "-s") then it would be
easy to enhance /etc/rc such that it could have an option to say "start
this thing, making sure all it's prerequisites are also already running."

Note I've had the following wee tiny hacks in my /etc/rc for a very long
time now which supports "debug" option to show what it would do as well
as another option to show which scripts are on or off via their
"rcvar".  (Yes, I have an fgrep binary in /bin too :-))

Index: rc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/master/m-NetBSD/main/src/etc/rc,v
retrieving revision 1.161
diff -u -r1.161 rc
--- rc	19 May 2002 01:01:32 -0000	1.161
+++ rc	31 Jul 2003 17:44:44 -0000
@@ -1,4 +1,4 @@
-#!/bin/sh
+#! /bin/sh
 #
 # $NetBSD: rc,v 1.161 2002/05/19 01:01:32 lukem Exp $
 #
@@ -11,8 +11,11 @@
=20
 export HOME=3D/
 export PATH=3D/sbin:/bin:/usr/sbin:/usr/bin
+
 umask 022
=20
+stty status '^T'
+
 . /etc/rc.subr
 . /etc/rc.conf
 _rc_conf_loaded=3DYES
@@ -22,25 +25,44 @@
 	exit 1
 fi
=20
-if [ "$1" =3D autoboot ]; then
-	autoboot=3Dyes
-	rc_fast=3Dyes	# run_rc_command(): do fast booting
-fi
+debug_echo=3D""
+_rc_run_command=3D"start"
=20
-stty status '^T'
+case "$1" in
+autoboot)
+	autoboot=3Dyes
+	_rc_fast_run=3Dyes	# run_rc_command(): do fast booting
+	;;
+rcvar)
+	_rc_run_command=3D"rcvar"
+	;;
+-d)
+	debug_echo=3Decho
+	;;
+esac
=20
-#	Set shell to ignore SIGINT, but not children;
-#	shell catches SIGQUIT and returns to single user.
+#	Set shell to ignore SIGINT (children will not ignore it though);
 #
 trap : INT
+
+#	Set shell to catch SIGQUIT and trigger a return to single user mode.
+#
+echo "Type a quit character (usually ^\\) to abort multi-user startup."
 trap "echo 'Boot interrupted.'; exit 1" QUIT
=20
 date
=20
-files=3D$(rcorder -s nostart ${rc_rcorder_flags} /etc/rc.d/*)
+_all_rc_d_files=3D""
+for _rc_d in /etc/rc.d ${more_rc_d} ; do
+	if [ -d $_rc_d -a ! -h $_rc_d -a ".$(echo ${_rc_d}/*)" !=3D ".${_rc_d}/\*=
" ]; then
+		_all_rc_d_files=3D"${_all_rc_d_files} $(ls -1d ${_rc_d}/* | fgrep -v -e =
/RCS -e /SCCS)"
+	fi
+done
+
+ordered_rc_d_files=3D$(rcorder -s nostart ${_all_rc_d_files})
=20
-for _rc_elem in $files; do
-	run_rc_script $_rc_elem start
+for _rc_elem in $ordered_rc_d_files; do
+	$debug_echo run_rc_script $_rc_elem $_rc_run_command
 done
=20
 date


--=20
						Greg A. Woods

H:+1 416 218-0098 W:+1 416 489-5852 x122 VE3TCP RoboHack <woods@robohack.ca>
Planix, Inc. <woods@planix.com>       Secrets of the Weird <woods@weird.com>

--pgp-sign-Multipart_Mon_Apr_23_14:13:56_2007-1
Content-Type: application/pgp-signature
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 5.0i for non-commercial use
MessageID: fNd3kaz1aROz8sFeNvxIbxjWpYx9C8km

iQA/AwUBRiz3ZmZ9cbd4v/R/EQLKBACgj5GxBj7v2RCp3uZoyAjv/4gq+uMAnjEN
hzAavrXrkOVkeByAOkCb5mcl
=xgTJ
-----END PGP SIGNATURE-----

--pgp-sign-Multipart_Mon_Apr_23_14:13:56_2007-1--