Getting sysrc to look in rc.conf.d files?

I'm in the process of reorganizing my rc stuff to take advantage of individual /etc/rc.conf.d files (as opposed to just using a monolithic /etc/rc.d). I just noticed something that surprised me, and I'm wondering if this is expected or not. If so, then if there's a way to get things to operate as *I* expected, and if not, then if there's something I might be doing wrong, or some other way to getting the information I want.

I executed sysrc unbound_enable, and was told "sysrc: unknown variable 'unbound_enable'". This is a variable that I am certain is now set in my /etc/rc.conf.d/unbound file rather than in /etc/rc.conf. Additionally, I'm virtually certain that the rc system knows about it, because if not, I have no idea how else unbound is successfully starting up at boot time, can be successfully interacted with via service unbound [I]whatever[/I], and so on.

It also does not show up in the output of sysrc -a (or of sysrc -A, but I would be really surprised if it did show up there).

This (unbound_enable) is just an example: Everything else defined in a /etc/rc.conf.d

I've checked man sysrc, and there I've seen various things mentioning /etc/rc.conf.d, but they don't seem to have anything to do with displaying variables contained therein.
 
Update: It occurred to me that my /etc/rc.conf.d files are actually symlinks, and a lot of things have problems (intentionally or not) handling symlinks. So I replaced the /etc/rc.conf.d/unbound symlink with an actual file, an exact copy of the file that the symlink had been pointing to. service still knows about unbound, but sysrc still does not. So "symlink" is not the problem (or at least not the only problem).
 
There is no automagic mapping sysrc(8) variable → dedicated /etc/rc.conf.d/… file. ? Therefore you need to specify the service(8) name (the file name in /etc/rc.conf.d) with -s.​
Bash:
sysrc -s unbound unbound_enable
To retrieve all non‑default sysrc(8) values including those set in /etc/rc.conf.d/…, you need to prevent glob(3) expansion in the invoking shell by wrapping pathnames into quotes. ? sysrc(8) itself is a shell script so it will handle expansion.​
Bash:
sysrc -a -f '/etc/rc.conf*' -f '/etc/rc.conf.d/*' -f '/etc/rc.conf.d/*/*'
sysrc(8) cannot automagically conclude unbound_enable shall be written to /etc/rc.conf.d/unbound instead of the generic /etc/rc.conf unless there is a pre‑existing assignment in /etc/rc.conf.d/unbound. ?​
Bash:
cat > /etc/rc.conf.d/foo << 'EOT' || exit 1
# empty file
EOT
# This gets written to /etc/rc.conf (the first -f file) even though /etc/rc.conf.d/foo exists.
sysrc -f '/etc/rc.conf' -f '/etc/rc.conf*' -f '/etc/rc.conf.d/*' -f '/etc/rc.conf.d/*/*' foo_enable='yes'
# Revert changes, remove the `foo_enable="yes"` line.
sysrc -x foo_enable


cat > /etc/rc.conf.d/foo << 'EOT'
foo_enable='I dunno'
EOT
# Same command as above, but now gets written to `/etc/rc.conf.d/foo`.
sysrc -f '/etc/rc.conf' -f '/etc/rc.conf*' -f '/etc/rc.conf.d/*' -f '/etc/rc.conf.d/*/*' foo_enable='yes'
To understand why some service gets started/configured it may be worthwhile to read rc.subr(8)outines and the actual file /etc/rc.subroutines.​
 
Back
Top