Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Mar 2003 15:12:16 -0600
From:      "Scot Hetzel" <hetzels@westbend.net>
To:        "Doug Barton" <DougB@FreeBSD.ORG>
Cc:        <freebsd-rc@yahoogroups.com>
Subject:   Re: port rc.d files
Message-ID:  <02ac01c2ea6e$6456fdc0$19fd2fd8@westbend.net>
References:  <20030313100830.GA30175@murmeldjur.it.su.se> <016b01c2e99d$51c24a60$19fd2fd8@westbend.net> <20030313231945.B1839@znfgre.tberna.bet>

next in thread | previous in thread | raw e-mail | index | archive | help

----- Original Message -----
From: "Doug Barton" <DougB@FreeBSD.ORG>
To: "Scot Hetzel" <hetzels@westbend.net>
Cc: "Richard Nyberg" <rnyberg@it.su.se>; <ports@FreeBSD.ORG>
Sent: Friday, March 14, 2003 1:20 AM
Subject: Re: port rc.d files


> On Thu, 13 Mar 2003, Scot Hetzel wrote:
>
> > RC_NG needs a new function added to rc.subr (load_local_rc_config)
>
> I disagree. I don't see any reason why the user and/or port couldn't do
> this in /etc/rc.conf.local.
>
Where does the Port Maintainer put the default settings for their ports rc.d
script.  We shouldn't have to hard code these settings into the rc.d script
and we are not supposed to be making changes in /etc if possible. The best
place to store these are in the ${prefix}/etc/rc.conf.d/scriptname file.
This allows us to document the available configuration variables for each
port, and allow the defaults to be overridden in  /etc/rc.conf.local or
/etc/rc.conf.  Otherwise we'll have to hardcode the default values into the
script.

With load_local_rc_config:

rc.conf.d/scriptname
    # Make changes to these default settings in /etc/rc.conf.local or
/etc/rc.conf.
    # Changes made to this file will be overwritten upon the next port
upgrade/re-install.
    #
    scriptname_enable="YES"        # Allow scriptname to start
    scriptname_flags="-a"               # Flags to scriptname
    scriptname_program="/path/to/command"
    :
    scriptname_exampled_enable="YES    # Enable starting of exampled
    scriptname_exampled_flags="-d"         # exampled run as daemon in
background
    :

rc.d/scriptname.sh
    #!bin/sh

    prefix=/usr/local

    . /etc/rc.subr

    name="scriptname"
    rcvar=`set_rcvar`
    command="/path/to/command
    load_local_rc_config $name
    run_rc_command "$1"

    name="scriptname_exampled"
    rcvar=`set_rcvar`
    command="/path/to/exampled"
    run_rc_command "$1"

As shown above a disclaimer is placed in the ports rc.conf .d/scriptname
files not to make changes to this file, but to place their changes in
/etc/rc.conf.local or /etc/rc.conf.

Without load_local_rc_config:

rc.d/scriptname.sh
    #!/bin/sh

    # You may need to define these variables in your /etc/rc.conf.local or
/etc/rc.conf files
    # scriptname_enable    -    Set to yes to enable ${scriptname_program}
    # scriptname_flags       -    Flags to execute program with
(default: -a)
    # scriptname_program -    Location of 'command' (default:
/path/to/command)
    :
    # scriptname_exampled_enable - Set to yes to enable the exampled daemon
    # scriptname_exampled_flags    - Flags to execute exampled with
(default: -d)
    :

    . /etc/rc.subr

    name="scriptname"
    rcvar=`set_rcvar`
    command="/path/to/command
    load_rc_config $name
    if [-z "${scriptname_flags}" ]; then
        scriptname_flags="-a"
    fi
    run_rc_command "$1"

    name="scriptname_exampled"
    rcvar=`set_rcvar`
    command="/path/to/exampled"
    if [-z "${scriptname_exampled_flags}" ]; then
        scriptname_exampled_flags="-d"
    fi
or
    #!/bin/sh

    . /etc/rc.subr

    name="scriptname"
    run_rc_command "$1"
    rcvar=`set_rcvar`
    command="/path/to/exampled"

    # default variable settings, redine these valuse in /etc/rc.conf.local
or /etc/rc.conf
    scriptname_enable="NO"
    scriptname_flags="-a"
    # scriptname_program=${command}

    load_rc_config $name
    run_rc_command "$1"

The problem with load_rc_config in rc.subr is that it will only read rc.conf
configuration files from /etc/defaults/rc.conf ${rc_conf_files} and
/etc/rc.conf.d/scriptname. But it won't read
${prefix}/etc/rc.conf.d/scriptname.

PR 44800 is a patch to add load_local_rc_config to rc.subr.  In order for
load_local_rc_config to work, the ports script needs to define 'prefix' to
the location to where ../etc/rc.conf.d/scriptname exists.

I had added a compatibily hack to the bottom of the load_local_rc_config
function that can be removed.  This hack made it so that if the *_enable
variables were undefined, it would default to YES, so that the script would
behave the same under pre-RC_NG (*_enable variables not used) and RC_NG.

In the ports that I had converted to RC_NG (see PR list in PR 44800), I had
to duplicate code in each of these ports rc.d scripts so they could read
their configuration variables from ${prefix}/etc/rc.conf.d/scriptname and
then from the standard rc.conf files.

Scot


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-ports" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?02ac01c2ea6e$6456fdc0$19fd2fd8>