Now let us add some controls to our dummy script. As you
may know, rc.d
scripts are controlled
with rc.conf(5). Fortunately, rc.subr(8) hides all
the complications from us. The following script uses
rc.conf(5) via rc.subr(8) to see whether it is
enabled in the first place, and to fetch a message to show
at boot time. These two tasks in fact are independent. On
the one hand, an rc.d
script can just
support enabling and disabling its service. On the other
hand, a mandatory rc.d
script can have
configuration variables. We will do both things in the same
script though:
#!/bin/sh . /etc/rc.subr name=dummy rcvar=dummy_enable start_cmd="${name}_start" stop_cmd=":" load_rc_config $name : ${dummy_enable:=no} : ${dummy_msg="Nothing started."} dummy_start() { echo "$dummy_msg" } run_rc_command "$1"
What changed in this example?
The variable | |
Now Note:While examining | |
A warning will be emitted by
Note:You can make rc.subr(8) act as though the knob
is set to
| |
Now the message to be shown at boot time is no
longer hard-coded in the script. It is specified by an
rc.conf(5) variable named Important:The names of all rc.conf(5) variables used
exclusively by our script must
have the same prefix: Note:While it is possible to use a shorter name internally,
e.g., just As a rule, | |
Here we use start_cmd="echo \"$dummy_msg\"" |
All FreeBSD documents are available for download at http://ftp.FreeBSD.org/pub/FreeBSD/doc/
Questions that are not answered by the
documentation may be
sent to <[email protected]>.
Send questions about this document to <[email protected]>.