From owner-freebsd-current Fri Oct 4 14: 4:36 2002 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D1BA137B404; Fri, 4 Oct 2002 14:04:29 -0700 (PDT) Received: from mail.westbend.net (ns1.westbend.net [216.47.253.3]) by mx1.FreeBSD.org (Postfix) with ESMTP id D69E843E4A; Fri, 4 Oct 2002 14:04:28 -0700 (PDT) (envelope-from hetzels@westbend.net) Received: from WBIw009.westbend.net (wbiw009 [216.47.253.29]) by mail.westbend.net (8.12.5/8.12.5) with ESMTP id g94L4RrH057903; Fri, 4 Oct 2002 16:04:28 -0500 (CDT) (envelope-from hetzels@westbend.net) Received: from WBIw009.westbend.net (localhost [127.0.0.1]) by WBIw009.westbend.net (8.12.6/8.12.6) with ESMTP id g94L4RJ0030874; Fri, 4 Oct 2002 16:04:27 -0500 (CDT) (envelope-from hetzels@westbend.net) Received: (from root@localhost) by WBIw009.westbend.net (8.12.6/8.12.6/Submit) id g94L4RgC030873; Fri, 4 Oct 2002 16:04:27 -0500 (CDT) Date: Fri, 4 Oct 2002 16:04:27 -0500 (CDT) Message-Id: <200210042104.g94L4RgC030873@WBIw009.westbend.net> From: "Scot W. Hetzel" To: FreeBSD-Current , Gordon Subject: RC_NG for local rc scripts X-Virus-Scanned: by amavisd-milter (http://amavis.org/) Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG I was looking at how the RC_NG base scripts work, and decide to try changing a few ports rc scripts to RC_NG. The process was simple enough to convert the security/cyrus_sasl{,2} (pwcheck.sh, saslauthd{1,}.sh), mail/cyrus_imapd{,2} (imapd.sh), net/openldap{,2} (slapd.sh) and databases/mysql323-{client,server} (mysql-client.sh, mysql-server.sh) scripts to RC_NG. One problem I found with in /etc/rc.subr is that load_rc_config can only get it's configuration data from /etc/{default/,}rc.conf and /etc/rc.conf.d/*. While local rc scripts should also be able to get their configuration data from ${prefix}/etc/rc.conf.d/*. At a minimum a local rc script would be: > cat example.sh #!/bin/sh # # PROVIDE: # REQUIRE: # BEFORE: [start before service] # KEYWORD: FreeBSD shutdown # # NOTE for FreeBSD 5.0+: # If you want this script to start with the base rc scripts # copy example.sh-sample to /etc/rc.d/example, otherwise # copy example.sh-sample to example.sh. prefix=%%PREFIX%% if [ -f /etc/rc.subr ]; then . /etc/rc.subr name="example" rcvar`set_rcvar` command="${prefix}/sbin/${name}" pidfile="/var/run/${name}.pid" load_local_rc_config ${name} run_rc_command ${name} else if [ -f ${prefix}/etc/rc.conf.d/${name} ]; then . ${prefix}/etc/rc.conf.d/${name} fi : old startup script fi Attached is a patch to /etc/rc.subr, that provides the load_local_rc_config routine. Ths routine loads the configuration data in the following order: ${prefix}/etc/rc.conf.d/* /etc/default/rc.conf /etc/rc.conf /etc/rc.conf.d/* This routine also checks the *_enable variable to see if it has been set, if not then the routine will set it to YES. This is only for compatibilty with the old local scripts. This check could be removed if compatiblity is not necessary. Scot Hetzel Index: rc.subr =================================================================== RCS file: /home/ncvs/src/etc/rc.subr,v retrieving revision 1.6 diff -u -r1.6 rc.subr --- rc.subr 12 Sep 2002 17:27:36 -0000 1.6 +++ rc.subr 3 Oct 2002 18:44:50 -0000 @@ -833,6 +833,45 @@ } # +# load_local_rc_config +# Source in the configuration file for a given local command. +# +# The following globals are used: +# +# Name Needed Purpose +# ---- ------ ------- +# prefix y Base directory that script is located in (i.e /usr/local) +# +# rcvar y Name of variable used to enable the service. If the enable +# variable is unset, then set it to YES. +# +load_local_rc_config() +{ + _command=$1 + if [ -z "$_command" ]; then + err 3 "USAGE: load_local_rc_config command" + fi + + if [ -f ${prefix}/etc/rc.conf.d/"$_command" ]; then + debug "Sourcing ${prefix}/etc/rc.conf.d/${_command}" + . ${prefix}/etc/rc.conf.d/"$_command" + fi + + # Let either /etc/rc.conf or /etc/rc.conf.d/"$_command" + # override ${prefix}/etc/rc.conf.d/"$_command" + load_rc_config $_command + + # Used for compatibilty with old behavior of local rc scripts. + if [ -n "$rcvar" ]; then + eval _value=\$${rcvar} + if [ -z "${_value}" ]; then + debug "load_local_rc_config: setting ${rcvar} to YES" + eval ${rcvar}=YES + fi + fi +} + +# # rc_usage commands # Print a usage string for $0, with `commands' being a list of # valid commands. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message