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: <what we provide>
    # REQUIRE: <LOGIN, DAEMON>
    # 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 [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to