Subject: rc local [patches]
To: None <tech-userlevel@NetBSD.org>
From: None <tlaronde@polynum.com>
List: tech-userlevel
Date: 03/18/2007 15:08:14
--opJtzjQTFsWo+cga
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

Hello,

Here is a set of patches to modify slightly rc framework local
additions.

Rationale
---------

The rc(8) framework offers several facilities, two important ones being
to launch services in topological order (via rcorder(8)), and to shut
down properly these services in reverse order when shutdown(8) is
invoked.

At the moment, the comments in /etc/rc.local do not emphasize the fact
that local daemons launched via this file will be launched when
/etc/rc.d/local is called with the start action, that is not mandatorily
at the better time for these daemons.
Furthermore, the sibling script /etc/rc.shutdown.local is not
advertised, while this is the script invoked when /etc/rc.d/local is
called with the stop action (i.e., for example, by shutdown(8)). It is
hence the natural place to put clean stopping actions for services
launched in /etc/rc.local. But a better practice for daemons is to have
rc.d compliant scripts.

One of the strength of the actual NetBSD etc/ organization is that it
insulates NetBSD provided stuff from local overwrites and additions.
/etc/rc.conf shall lists only the specific for this very site, the diff
from the defaults set in /etc/defaults/rc.conf.

If one wants to modify the behavior of a NetBSD provided service (i.e. a
script put in /etc/rc.d/), the /etc/rc.conf.d/ is provided.

Hence putting additional services in /etc/rc.d/ is perhaps not the best
maintenance option:
	1) postinstall(8) may suppress scripts in /etc/rc.d/ or an upgrade
	may add scripts there. What if a local addition happens to provide
	such a named script?
	2) the actual framework provides a great maintenance principle: the
	"coup d'oeil": in one glance, looking at dedicated places, one
	easily knows what are the very specifics of this site, the diffs from
	a default install. Putting local additions in /etc/rc.d/ makes it
	hard to find, after some time, what is a default provided by NetBSD
	and a local addition. It does not scale.

Hence putting local added daemons in a dedicated directory is cleaner,
and actually straightforward: a one line diff to rc(8).

Putting the maintenance reflexion a little further, one sees that if the
NetBSD provided services defaults are clearly documented in
/etc/defaults/rc.conf, local additions will not have that, or these
defaults will end in /etc/rc.conf, putting a lot of verbosity and
masking the real, raw diffs: if one needs to start grepping all around
to find what is launched and what is not, we loose the "coup d'oeil"
facility.

Furthermore, say in a network (in a domain), an administrator may have
configuration habits. It would be simpler to have in /etc/rc.conf only
what makes this very node different from:
	a) the default NetBSD;
	b) the default domain configuration.

Hence the introduction of /etc/rc.defaults.local that shall document, 
la /etc/defaults/rc.conf, the setting of local added services in
/etc/rc.d.local/, and provide a domain wide default configuration.

Tree and namespace principles
-----------------------------

Joerg Sonnenberger and Thor Lancelot Simon have rightfully reacted
against some of my early naming scheme proposals (I do not claim that
they have voiced for or against this proposal; I just give them the
credit that they did not find the naming scheme correct).

So here are the principles adopted:

1) All local "hooks" are visible at the /etc/ root, whether files or
directories;

2) All names are built appending ".local" to them, since the emphasis
must be put not on the nature of a link (a file or a directory '.d') but
on the fact that these are local versions of standard facilities.
	There is also prior art since the script sourced by /etc/rc.d/local
	stop is called "/etc/rc.shutdown.local"

Added files and directories
---------------------------

/etc/rc.d.local         # directory for local added services
/etc/rc.defaults.local  # domain wide variables setting  la
                        # /etc/defaults/rc.conf. Sourced, if readable,
						# in /etc/rc.conf.
/etc/rc.shutdown.local  # missing template for script sourced when
                        # /etc/rc.d/local stop

Caveats
-------

I have diffed against 3.1. This should not cause problem except
for rc.conf(5) that has, obviously, changed in head. But should applies
nonetheless.

I am not an english native speaker so, assuming that my proposal makes
some sense, the comments in the scripts and the man pages modifications
should be reviewed and enhanced.

Thanks for your time.
-- 
Thierry Laronde (Alceste) <tlaronde +AT+ polynum +dot+ com>
                 http://www.kergis.com/
Key fingerprint = 0FF7 E906 FBAF FE95 FD89  250D 52B1 AE95 6006 F40C

--opJtzjQTFsWo+cga
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=diff

diff -ru /usr/src/distrib/sets/lists/base/mi ./distrib/sets/lists/base/mi
--- /usr/src/distrib/sets/lists/base/mi	2006-11-27 15:25:18.000000000 +0100
+++ ./distrib/sets/lists/base/mi	2007-03-18 13:21:34.000000000 +0100
@@ -89,6 +89,7 @@
 ./etc/release					etc-sys-etc
 ./etc/rc.conf.d					base-sys-root
 ./etc/rc.d					base-sys-root
+./etc/rc.d.local					base-sys-root
 ./etc/skel					base-sys-root
 ./etc/sliphome					base-slip-root
 ./etc/ssh					base-sys-root
diff -ru /usr/src/etc/changelist ./etc/changelist
--- /usr/src/etc/changelist	2001-10-13 16:22:11.000000000 +0200
+++ ./etc/changelist	2007-03-18 13:19:30.000000000 +0100
@@ -10,4 +10,5 @@
 #	/etc/raid*.conf
 #	/etc/rc.d/*
 #	/etc/rc.conf.d/*
+#	/etc/rc.d.local/*
 #
diff -ru /usr/src/etc/mtree/NetBSD.dist ./etc/mtree/NetBSD.dist
--- /usr/src/etc/mtree/NetBSD.dist	2006-05-26 14:17:03.000000000 +0200
+++ ./etc/mtree/NetBSD.dist	2007-03-18 13:20:24.000000000 +0100
@@ -42,6 +42,7 @@
 ./etc/racoon
 ./etc/rc.conf.d
 ./etc/rc.d
+./etc/rc.d.local
 ./etc/skel
 ./etc/sliphome
 ./etc/ssh
diff -ru /usr/src/etc/rc ./etc/rc
--- /usr/src/etc/rc	2003-01-04 16:27:43.000000000 +0100
+++ ./etc/rc	2007-03-17 20:25:33.000000000 +0100
@@ -37,7 +37,8 @@
 
 date
 
-files=$(rcorder -s nostart ${rc_rcorder_flags} /etc/rc.d/*)
+files=$(rcorder -s nostart ${rc_rcorder_flags} /etc/rc.d/* \
+	/etc/rc.d.local/*)
 
 for _rc_elem in $files; do
 	run_rc_script $_rc_elem start
diff -ru /usr/src/etc/rc.conf ./etc/rc.conf
--- /usr/src/etc/rc.conf	2000-10-14 19:01:29.000000000 +0200
+++ ./etc/rc.conf	2007-03-18 12:24:45.000000000 +0100
@@ -13,9 +13,17 @@
 	. /etc/defaults/rc.conf
 fi
 
+# Load local domain wide defaults in from /etc/rc.defaults.local (if 
+# it's readable).
+# These can be overridden too below.
+#
+if [ -r /etc/rc.defaults.local ]; then
+	. /etc/rc.defaults.local
+fi
+
 # If this is not set to YES, the system will drop into single-user mode.
 #
 rc_configured=NO
 
-# Add local overrides below
+# Add site specific overrides below
 #
diff -ru /usr/src/etc/rc.local ./etc/rc.local
--- /usr/src/etc/rc.local	2002-07-23 12:48:01.000000000 +0200
+++ ./etc/rc.local	2007-03-18 12:20:10.000000000 +0100
@@ -1,22 +1,43 @@
-#	$NetBSD: rc.local,v 1.30 2002/07/23 10:48:01 wennmach Exp $
+#	$Id$
 #	originally from: @(#)rc.local	8.3 (Berkeley) 4/28/94
 #
-# This file is (nearly) the last thing invoked by /etc/rc during a
-# normal boot, via /etc/rc.d/local.
+# This file is what is invoked by /etc/rc.d/local when given the start
+# action.
 #
-# It is intended to be edited locally to add site-specific boot-time
-# actions, such as starting locally installed daemons.
+# So actions declared here will take place in the boot process at the 
+# place assigned by rcorder(8) to /etc/rc.d/local, that is relatively 
+# late in the booting process.
 #
-# An alternative option is to create site-specific /etc/rc.d scripts.
+# It is intended to be edited locally to add site-specific user
+# interface tuning, such as audio output etc. but is not limited to
+# that.
+#
+# While you can add local daemons here, it is better practice to use
+# the rc framework since, as mentioned above, this file will be treated
+# at a time matching /etc/rc.d/local requisites, and this order may or 
+# may not match your daemons requisites.
+# Furthermore, by placing rc compliant scripts in /etc/rc.d.local/,
+# local services will be cleanly and in the correct order stopped by
+# the rc framework when shutdown(8) is used.
+#
+# The sibling file /etc/rc.shutdown.local is what is invoked by
+# etc/rc.d/local when given the stop action (this is the case when
+# shutdown(8) is used). So if you have decided to launch specific 
+# services here, you might be interested in stopping them cleanly by 
+# adding the required actions in this file.
 #
 
-echo -n 'Starting local daemons:'
+echo -n 'Starting site specific user interface tuning:'
 
-# Add your local daemons here.
+# Add your tuning here
 #
 
-#if [ -f /usr/pkg/etc/rc.d/apache ]; then
-#	/usr/pkg/etc/rc.d/apache start
-#fi
+# audio stuff
+#audioctl -d /dev/sound0 -w play=44100,2,16,slinear_le
+#mixerctl -w outputs.master=191,191
+
+# set font to vt220iso8x16 (latin1)
+#for device in /dev/ttyE1 /dev/ttyE2 /dev/ttyE3 /dev/ttyE4; do
+#	wsconsctl -f $device -dw font=vt220iso8x16
+#done
 
-echo '.'
diff -ru /usr/src/etc/security ./etc/security
--- /usr/src/etc/security	2006-11-27 15:25:25.000000000 +0100
+++ ./etc/security	2007-03-18 13:18:35.000000000 +0100
@@ -901,11 +901,13 @@
 		#	/etc/raid*.conf
 		#	/etc/rc.d/*
 		#	/etc/rc.conf.d/*
+		#	/etc/rc.d.local/*
 		#
 		echo "/etc/ifconfig.*"
 		echo "/etc/raid*.conf"
 		echo "/etc/rc.d/*"
 		echo "/etc/rc.conf.d/*"
+		echo "/etc/rc.d.local/*"
 
 		# Add /etc/changelist
 		#
diff -ru /usr/src/share/man/man5/rc.conf.5 ./share/man/man5/rc.conf.5
--- /usr/src/share/man/man5/rc.conf.5	2006-11-27 15:29:56.000000000 +0100
+++ ./share/man/man5/rc.conf.5	2007-03-18 14:08:48.000000000 +0100
@@ -32,7 +32,7 @@
 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 .\" SUCH DAMAGE.
 .\"
-.Dd March 27, 2006
+.Dd March 18, 2007
 .Dt RC.CONF 5
 .Os
 .Sh NAME
@@ -61,7 +61,7 @@
 variables that may be set, the values to which each may be set,
 a brief description of what each variable does, and a reference to
 relevant manual pages.
-Third party packages may test for additional variables.
+Third party packages may test for additional variables. 
 .Pp
 Most variables are one of two types: enabling variables or flags
 variables.
@@ -87,9 +87,19 @@
 reads
 .Pa /etc/defaults/rc.conf
 (if it is readable)
-to obtain default values for various variables, and the end-user
+to obtain default values for various variables and 
+.Pa /etc/rc.defaults.local
+(if it is readable)
+for domain wide local various variables (including, probably, the ones
+used for services put in
+.Pa /etc/rc.d.local/
+) and the end-user
 may override these by appending appropriate entries to the end of
 .Nm .
+Variables set in
+.Pa /etc/rc.defaults.local
+shall respect the overall rc framework, but only the standard 
+configuration is discussed below.
 .Pp
 .Xr rc.d 8
 scripts that use
diff -ru /usr/src/share/man/man8/rc.8 ./share/man/man8/rc.8
--- /usr/src/share/man/man8/rc.8	2004-01-06 15:46:11.000000000 +0100
+++ ./share/man/man8/rc.8	2007-03-18 14:14:45.000000000 +0100
@@ -34,18 +34,20 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd January 6, 2004
+.Dd March 18, 2006
 .Dt RC 8
 .Os
 .Sh NAME
 .Nm rc ,
 .Nm rc.shutdown ,
-.Nm rc.d/
+.Nm rc.d/,
+.Nm rc.d.local/
 .Nd startup and shutdown scripts
 .Sh SYNOPSIS
 .Nm rc
 .Nm rc.shutdown
 .Nm rc.d/
+.Nm rc.d.local/
 .Sh DESCRIPTION
 .Nm
 is the command script which controls the startup of various services,
@@ -68,8 +70,13 @@
 .Nm rc.d/
 is the directory which contains various
 .Xr sh 1
-scripts, one for each service,
-which are called by
+scripts, one for each standard provided service,
+and
+.Nm rc.d.local/
+is the directory which contains various
+.Xr sh 1
+scripts for local added services,
+which are all called by
 .Nm
 at startup,
 .Nm rc.shutdown
@@ -91,6 +98,8 @@
 .Sy ( rc_fast=yes ) ,
 which prevents the
 .Nm rc.d
+or
+.Nm rc.d.local
 scripts from performing the check for already running processes
 (thus speeding up the boot process).
 This
@@ -103,6 +112,9 @@
 .Xr rcorder 8
 to order the files in
 .Pa /etc/rc.d/
+and
+.Pa /etc/rc.d.local/
+
 that do not have a
 .Dq nostart
 keyword (refer to
@@ -135,6 +147,8 @@
 .Xr rcorder 8
 to order the files in
 .Pa /etc/rc.d/
+and
+.Pa /etc/rc.d.local/
 that have a
 .Dq shutdown
 keyword (refer to
@@ -231,6 +245,9 @@
 Note that this should be used extremely sparingly!
 .El
 .Pp
+The following description applies as well to scripts put in
+.Pa /etc/rc.d.local/ .
+.Pp
 Each script should contain
 .Xr rcorder 8
 keywords, especially an appropriate
@@ -307,7 +324,9 @@
 Startup script called by
 .Xr init 8 .
 .It Pa /etc/rc.d/
-Directory containing control scripts for each service.
+Directory containing control scripts for each standard service.
+.It Pa /etc/rc.d.local/
+Directory containing control scripts for each locally added service.
 .It Pa /etc/rc.shutdown
 Shutdown script called by
 .Xr shutdown 8 .
--- /usr/src/etc/rc.shutdown.local	1970-01-01 01:00:00.000000000 +0100
+++ etc/rc.shutdown.local	2007-03-18 12:22:30.000000000 +0100
@@ -0,0 +1,9 @@
+#	$Id$
+#
+# This file is what is invoked by /etc/rc.d/local when given the stop
+# action. This is automatically the case when shutdown(8) is used.
+#
+# So you can place here whatever action you may see fit when shutting
+# down and specifically, if you have launched some services in
+# /etc/rc.local, you can add here actions to stop them cleanly.
+#

--opJtzjQTFsWo+cga--