Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 28 Jul 2004 17:16:50 +0200
From:      Oliver Eikemeier <eikemeier@fillmore-labs.com>
To:        freebsd-rc@FreeBSD.org
Subject:   RFC: Alternate patch to have true new-style rc.d scripts in ports
Message-ID:  <4107C362.6030101@fillmore-labs.com>

next in thread | raw e-mail | index | archive | help
Appended is an alternate patch to have true new-style rc.d scripts in 
ports. Scripts in ${local_startup} are processed as follows:

- scripts ending in .sh are treated as old-style scripts, which means 
they need to have it's executable bit set to be considered by localpkg 
as before. Whether they partially use rc.subr features or not isn't 
relevant. They are executed in lexicographical order like specified in 
rc(8).

- scripts without any extension participate in a system wide rcorder(8). 
To enable diskless booting and remote mounting they are not executed 
before a configurable barrier script ${rclocal_barrier} is executed, 
which is PORTS is this patch. Whether or not the script is has it's 
executable bit set is not examined.

I'm not sure if we should filter out *all* scripts with extensions. 
There might be a startup.app port we like to add, perhaps just a list of 
values like `.old', `.sample' e.t.c. should be filtered out. OTOH this 
is easily changeable, should the need arise.

Also we could set the default of rclocal_barrier to be `LOGIN' in case 
we are not sure what the effects of starting ports early is. Users who 
know their files systems are all local could even set rclocal_barrier to 
be an earlier value. Perhaps the dummy `ports' target isn't needed at 
all and simply using `SERVERS' will do the trick.

I would prefer a testing period, but this patch could go into the tree 
every time since it does not break backwards compatibility. We can add 
the necessary infrastructure to bsd.port.mk, and slowly migrate the 
ports to extensionless startup scripts. New -CURRENTs can continue to 
use old or already installed packages, while older systems will ignore 
the startup scripts in packages build on newer systems. I guess a 
heads-up might be sufficient to deal with the later case, adding a 
pkg_req script to every package seems to be too much effort for too 
little gain.

The bsd.port.mk integration might be something like

RC_SCRIPTS=	apache

which will install `apache' or `apache.sh' depending on OSVERSION. A 
variable RC_SUFX is set that could be used in pkg-message or other 
places when necessary.

Sourcing port scripts is not possible with this patch, which is a good 
thing IMHO. Also some documentation needs to added to rc(8) before this 
patch can go in.

-Oliver


Index: etc/rc
===================================================================
RCS file: /home/ncvs/src/etc/rc,v
retrieving revision 1.333
diff -u -u -r1.333 rc
--- etc/rc	24 Jul 2004 16:30:31 -0000	1.333
+++ etc/rc	28 Jul 2004 14:13:27 -0000
@@ -70,6 +70,44 @@
 [ `/sbin/sysctl -n security.jail.jailed` -eq 1 ] && skip="$skip -s nojail"
 files=`rcorder -k ${os} ${skip} /etc/rc.d/* 2>/dev/null`
 
+# execute startup scripts up to rclocal_barrier (which is available after rcconf.sh)
+_rc_done=""
+for _rc_elem in ${files}; do
+	run_rc_script ${_rc_elem} ${_boot}
+	_rc_done="${_rc_done}${_rc_elem} "
+	if [ "/${_rc_elem##*/}" = "/${rclocal_barrier-}" ]; then
+		break
+	fi
+done
+
+# enough of the system is up to include local_startup in rcorder
+case ${local_startup} in
+[Nn][Oo] | '')
+	;;
+*)
+	_rc_startup="/etc/rc.d/*"
+	for dir in ${local_startup}; do
+		[ -d "${dir}" ] || continue
+		for script in "${dir}"/*; do
+			case "${script##*/}" in
+			*.*)	;;
+			*)	if [ -f "${script}" ]; then
+					_rc_startup="${_rc_startup} ${script}"
+				fi ;;
+			esac
+		done
+	done
+	files=`rcorder -k ${os} -s nostart ${_rc_startup} 2>/dev/null`
+esac
+
+# execute the remaining startup scripts, avoiding duplicates
+files=`echo "${_rc_done}<> ${files}" |
+	tr -s ' ' '\n' |
+	awk '
+		/^<>$/ {exec=1; next}
+		!exec {done[$0]=1; next}
+		!done[$0] {print}
+	'`
 for _rc_elem in ${files}; do
 	run_rc_script ${_rc_elem} ${_boot}
 done
Index: etc/rc.shutdown
===================================================================
RCS file: /home/ncvs/src/etc/rc.shutdown,v
retrieving revision 1.27
diff -u -u -r1.27 rc.shutdown
--- etc/rc.shutdown	26 Jun 2004 09:27:30 -0000	1.27
+++ etc/rc.shutdown	28 Jul 2004 11:51:47 -0000
@@ -82,7 +82,24 @@
 # XXX - rcorder(8) with multiple -k switches works as a logical OR,
 #       so, we can't do this: rcorder -k shutdown -k FreeBSD.
 #
-files=`eval grep -l \'^# KEYWORD:.*FreeBSD\' \`rcorder -k shutdown /etc/rc.d/* 2>/dev/null\``
+_rc_startup="/etc/rc.d/*"
+case ${local_startup} in
+[Nn][Oo] | '')
+	;;
+*)
+	for dir in ${local_startup}; do
+		[ -d "${dir}" ] || continue
+		for script in "${dir}"/*; do
+			case "${script##*/}" in
+			*.*)	;;
+			*)	if [ -f "${script}" ]; then
+					_rc_startup="${_rc_startup} ${script}"
+				fi ;;
+			esac
+		done
+	done
+esac
+files=`eval grep -El \'^# KEYWORDS?:.*FreeBSD\' \`rcorder -k shutdown ${_rc_startup} 2>/dev/null\``
 
 for _rc_elem in `reverse_list $files`; do
 	debug "run_rc_script $_rc_elem faststop"
Index: etc/defaults/rc.conf
===================================================================
RCS file: /home/ncvs/src/etc/defaults/rc.conf,v
retrieving revision 1.212
diff -u -u -r1.212 rc.conf
--- etc/defaults/rc.conf	27 Jul 2004 00:28:16 -0000	1.212
+++ etc/defaults/rc.conf	28 Jul 2004 11:58:52 -0000
@@ -46,6 +46,7 @@
 local_startup="/usr/local/etc/rc.d /usr/X11R6/etc/rc.d" # startup script dirs.
 script_name_sep=" "	# Change if your startup scripts' names contain spaces
 rc_conf_files="/etc/rc.conf /etc/rc.conf.local"
+rclocal_barrier="PORTS"	# Barrier for local_startup scripts to participate in rcorder(8)
 
 # Experimental - test before enabling
 gbde_autoattach_all="NO" # YES automatically mounts gbde devices from fstab
Index: etc/rc.d/Makefile
===================================================================
RCS file: /home/ncvs/src/etc/rc.d/Makefile,v
retrieving revision 1.41
diff -u -u -r1.41 Makefile
--- etc/rc.d/Makefile	24 May 2004 14:17:19 -0000	1.41
+++ etc/rc.d/Makefile	28 Jul 2004 13:39:43 -0000
@@ -1,7 +1,7 @@
 # $NetBSD: Makefile,v 1.16 2001/01/14 15:37:22 minoura Exp $
 # $FreeBSD: src/etc/rc.d/Makefile,v 1.41 2004/05/24 14:17:19 des Exp $
 
-FILES=	DAEMON LOGIN NETWORKING SERVERS \
+FILES=	DAEMON LOGIN NETWORKING PORTS SERVERS \
 	abi accounting addswap adjkerntz amd \
 	apm apmd archdep atm1 atm2 atm3 \
 	bgfsck bootparams \
Index: etc/rc.d/PORTS
===================================================================
RCS file: etc/rc.d/PORTS
diff -N etc/rc.d/PORTS
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ etc/rc.d/PORTS	28 Jul 2004 14:57:58 -0000
@@ -0,0 +1,12 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+# PROVIDE: PORTS
+# REQUIRE: mountcritremote
+# BEFORE: SERVERS
+# KEYWORD: FreeBSD
+
+#	This is a dummy dependency, marking earliest
+#	moment ports can participate in rcorder(8)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4107C362.6030101>