Subject: Re: rc.local and rcorder(8)
To: Manuel Bouyer <bouyer@antioche.lip6.fr>
From: Tero Kivinen <kivinen@ssh.fi>
List: current-users
Date: 07/03/2002 15:55:42
woods@weird.com (Greg A. Woods) writes:
> It also helps to have a "debug" option to /etc/rc that'll cause it to
> print what it'll do instead of doing it.  That way anyone can find out
> in what order all the scripts will be invoked.  I think I've posted this
> suggestion several times before....  :-)

I had some problems with my /etc/rc.d/* scripts, and I created
following debug mode for them. If the verify_rc_commands is set to YES
(the default should be NO in the /etc/defaults/rc.conf) then it will
print out prompt before running any /etc/rc.d/* scripts. Typing y +
enter or just enter will execute the given /etc/rc.d script and give
next prompt. "n" will skip that script (useful if you don't want to
start xdm etc when debugging rest of the /etc/rc.d/* scripts). "all"
will run rest of the /etc/rc.d/* scripts without prompting and "end"
will skip rest of them. "sh" will give you sub shell to check things
out, and "-x" will run the script with sh -x, i.e show what is going
on with the script (this was the thing I was mainly using, when trying
to find out what was wrong in one particular script).

Typing "/foo" + enter will search for /etc/rc.d/* script that will
start with foo and run everything up to that but do not execute it.
I.e type "/named" + enter + "-x" + enter to debug the /etc/rc.d/named
script... 

Index: rc
===================================================================
RCS file: /cvsroot/basesrc/etc/rc,v
retrieving revision 1.161
diff -u -u -r1.161 rc
--- rc	2002/05/19 01:01:32	1.161
+++ rc	2002/07/03 12:48:24
@@ -40,7 +40,35 @@
 files=$(rcorder -s nostart ${rc_rcorder_flags} /etc/rc.d/*)
 
 for _rc_elem in $files; do
-	run_rc_script $_rc_elem start
+	_rc_skip=0
+	if [ "x$_rc_search" != "x" ]; then 
+		case "$_rc_elem" in
+		# Note, this matches, because the _rc_search has / as a first
+		# character, thus */xxx matches to the /etc/rc.d/xxx.
+		*$_rc_search)  _rc_search='' ;;
+		esac
+	fi
+	if checkyesno verify_rc_commands; then
+		if [ "x$_rc_search" = "x" ]; then
+			echo -n "Execute $_rc_elem (Y/n/-x/all/end/sh) *> "
+			read _rc_question
+			case "$_rc_question" in
+			n|N) _rc_skip=1 ;;
+			-x)  set -x
+			     run_rc_script $_rc_elem start
+			     set +x
+			     _rc_skip=1
+			     ;;
+			all) verify_rc_commands=NO ;;
+			end) break ;;
+			/*)  _rc_search="$_rc_question" ;;
+			sh) /bin/sh ;;
+			esac
+		fi
+	fi
+	if [ $_rc_skip != 1 ]; then
+		run_rc_script $_rc_elem start
+	fi
 done
 
 date

-- 
kivinen@ssh.fi                               Work : +358 303 9870
SSH Communications Security                  http://www.ssh.fi/
SSH IPSEC Toolkit                            http://www.ssh.fi/ipsec/