editing rc.conf: any tool?

After years of manually editing /etc/rc.conf I realized that there could be some tool to get/set rcvars, but I don't know if there is any. I know service has a rcvars option to retrieve variables, but I cannot figure out if there is a tool to edit them in place.
Any suggestion?
 
Shame on me, I missed in the SEE ALSO section of rc().

Anyway, I don't see a clear way to inspect a single service variables, except for sysrc -a and a grep, is there a smarter approach?
 
I'm going to mildly disagree with Alain De Vos up in #6. Technically rc.conf is a config file that contains variable and value pairs that gets sourced by shell scripts (init scripts in /etc/rc.d and others).
I know it's splitting hairs because any file that you source in a shell script is treated as a shell script and in that context rc.conf defines variables.

That said, I'm old school and have been using vi to edit /etc/rc.conf for a long time. I like to comment things, I'll even go and add dates when I add or change things. sysrc is nice if you are automating things (like an installer or from a package) but the syntax of the file is not really hard. get the variable names correct (spelling, capitalization), then an equal sign, then double quote, then value, double quote to close.
 
sysrc(8) is useful in scripts to automatically add/remove things from rc.conf. Still quite useful to use interactively though. Although I'm pretty old-school (the sysrc(8) tool is a fairly recent addition) and just use an editor.

Yes, I see from the man page that it has been added in not so old versions of FreeBSD.

sysrc mysql_enable ppp_profile

mysql_enable: YES

ppp_profile: telco

I may have explained myself not very well: I was interested in "knowing" all possible variables of a service without having to manually look at it. For example, say I would see what can be tuned with postgresql_*, is there a way to get such definitions? So far it seems to me only using sysrc -A | grep postgresql.
 
i don't think so
you have to inspect the service launch script
That's a key piece of info people miss: most/all of the service scripts I've looked at (the ones from base plus whatever I installed) the variables and their possible values are usually listed and commented.
rc.conf can get you what values you have set, but not "all possible variables and possible values for a given service".
 
So far, I always had a look at rc scripts to see variables, but I think that something more like OpeNBSD's rcctl could be useful (no flame intended):

Code:
% doas rcctl getdef postgresql
postgresql_class=daemon
postgresql_flags=-D /var/postgresql/data -w -l /var/postgresql/logfile
postgresql_logger=
postgresql_rtable=0
postgresql_timeout=30
postgresql_user=_postgresql
 
That's a nice command. Quick look at the man page it seems to be a combination of sysrc and service.
man sysrc shows the options -a and -A which look like it returns "non service specific values" so it could be simply adding an optional service name to those command options.
 
run:
sh rcxxx.sh isc-dhcpd
==========
Code:
~$./rcxxx.sh isc-dhcpd
dhcpd_chroot_enable=NO
dhcpd_chrootdir=''
dhcpd_chuser_enable=no
dhcpd_conf=/usr/local/etc/dhcpd.conf
dhcpd_confdir=/usr/local/etc
dhcpd_conffile=/usr/local/etc/dhcpd.conf
dhcpd_devfs_enable=NO
dhcpd_leasesdir=/var/db
dhcpd_leasesfile=/var/db/dhcpd.leases
dhcpd_piddir=/var/run
dhcpd_pidfile=/var/run/dhcpd.pid
dhcpd_withumask=022
==========
Code:
#!/bin/sh
test ".$INNERCALL" = .YES || {
    export INNERCALL=YES
    cat "$0" | /bin/sh -s -c : /usr/local/etc/rc.d/$1 "$@"
    exit $?
}
_rc_subr_loaded="YES"
run_rc_command()
{
}
load_rc_config()
{
}
checkyesno()
{
return 1
}
[ $(id -u) -eq  0 ] && echo "Don't run $0 as root" && exit 1
set -- /usr/local/etc/rc.d/$1
. $1
IFS="
"
for line in $(set)
do
left=${line%%=*}
right=${line#*=}
[ "$left" = "${name}_enable" ] && continue
trunc=${left#$name}
[ "$trunc" != "$left" ] && echo $line
done
IFS=$_IFS
 
  • Like
Reactions: mer
With rc.conf being just a text file, you can get as fancy as you want with sed, awk, cut, echo, etc. But for simplicity, there's always the option to just use a text editor. rc.conf is not tied to any particular tool. As long as you get the syntax of the contents correct, that's all you need. Kinda demonstrates the flexibility of UNIX - you got all these options, they all work, and don't get in each other's way! :p
 
Back
Top