[nycbug-talk] rc.conf / rc'ng hacking

Matthew Story matt at tablethotels.com
Thu Oct 13 13:53:03 EDT 2011


Should have been a little more explicit about how I was thinking of using the rc.conf and ability to `.' to solve your particular problem:

was thinking you could basically ship config files with directives per NIC architecture along with your other files, for example:

rc.conf.local.0x10c9

and then by do a lookup of your system architecture to determine which config is correct (this one uses the device setting of the first ign pnpinfo directive, but you could key it on whatever you are looking for)

sysctl -a | awk -F ':' '
    /^dev\.igb.*pnpinfo/ { 
        split($2, a, /[ =]/); 
        for (i in a) { 
            if (grab) { 
                print "/etc/rc.conf.local."a[i]; break; 
            } 
            if (a[i] == "device") grab=1; 
        } 
        exit 0; 
     }' | xargs -n 1 -I% sudo ln % /etc/rc.conf.local

this same pattern works for the per rc service approach as well

sysctl -a | awk -F ':' '
    /^dev\.igb.*pnpinfo/ { 
        split($2, a, /[ =]/); 
        for (i in a) { 
            if (grab) { 
                print a[i]; break; 
            } 
            if (a[i] == "device") grab=1; 
        } 
        exit 0; 
     }' | xargs -n 1 sudo sh -c '
         for service in apache sendmail; do
             ln "/etc/rc.conf.$service.$1" "/etc/rc.conf.$service"
         done' 'config-linker'

Then just use the pattern in /etc/rc.conf:

[ -r "/etc/rc.conf.apache" ] && . "/etc/rc.conf.apache"
[ -r "/etc/rc.conf.sendmail" ] && . "/etc/rc.conf.apache"

Then you only have to re-run either of the above commands whenever you swap out your NIC, and don't have to put the lookup and resulting control-flow logic in the config itself.

On Oct 13, 2011, at 12:02 PM, Matthew Story wrote:

> 
> On Oct 13, 2011, at 11:32 AM, Mark Saad wrote:
>> So I was tired,lazy yesterday and I was wondering how does rc'ng
>> handle this , surely there has to be a rc'ng function to suck in from
>> rc.subr that I can call to get my nic type etc . I cant find anything,
>> can someone shed some light on how this handled ? Is there an easier
>> way to this ?
> 
> you could use /etc/rc.conf.local, from man 5 rc.conf
> 
>     The /etc/rc.conf file is included from the file /etc/defaults/rc.conf,
>     which specifies the default settings for all the available options.
>     Options need only be specified in /etc/rc.conf when the system adminis-
>     trator wishes to override these defaults.  The file /etc/rc.conf.local is
>     used to override settings in /etc/rc.conf for historical reasons.  See
>     the rc_conf_files variable below.
> 
> if you need more facility than that, you can alter the rc_conf_files variable in /etc/defaults/rc.conf:
> 
> rc_conf_files="/etc/rc.conf /etc/rc.conf.local"
> 
> for your inst script, you could start with the old rc_conf_files setting, and then  ...
> 
> awk -F '=' 'BEGIN { OFS=FS; } $1 == "rc_conf_files" { sub(/\"$/, " my.rc.conf.local\"", $2); } { print; }' /etc/defaults/rc.conf > /etc/defaults/rc.conf.new && mv /etc/defaults/rc.conf.new /etc/defaults/rc.conf
> 
> will add 'my.rc.conf.local" to the rc_conf_files string.  As rc conf files are just shell, you could cp the rc_conf_files functionallity from defaults to your /etc/rc.conf file and preserve the defaults file (as suggested in the defaults documentation), relevant code from rc.conf below:
> 
> ##############################################################
> ### Define source_rc_confs, the mechanism used by /etc/rc.* ##
> ### scripts to source rc_conf_files overrides safely.       ##
> ##############################################################
> 
> if [ -z "${source_rc_confs_defined}" ]; then
>    source_rc_confs_defined=yes
>    source_rc_confs () {
>        local i sourced_files
>        for i in ${rc_conf_files}; do
>            case ${sourced_files} in
>            *:$i:*)                ;;  
>            *)  
>                sourced_files="${sourced_files}:$i:"
>                if [ -r $i ]; then
>                    . $i
>                fi  
>                ;;              esac
>        done
>    }   
> fi
> 
> if you care less for safety, you can just:
> 
> [ -r "rc.special.conf" ] && . "rc.special.conf"
> 
> or in your /etc/rc.conf, breakout your service daemon specific configs and then do the same pattern:
> 
> # for apache
> [ -r "/etc/rc.conf.apache" ] && . "/etc/rc.conf.apache"
> # for sendmail
> [ -r "/etc/rc.conf.sendmail" ] && . "/etc/rc.conf.sendmail"
> # etc ...
> 
> 
>> 
>> ---
>> Mark Saad | mark.saad at ymail.com
>> _______________________________________________
>> talk mailing list
>> talk at lists.nycbug.org
>> http://lists.nycbug.org/mailman/listinfo/talk
>> 
> 
> best of luck.
> 
> -matt
> _______________________________________________
> talk mailing list
> talk at lists.nycbug.org
> http://lists.nycbug.org/mailman/listinfo/talk
> 




More information about the talk mailing list