6.15 Starting and stopping services (rc scripts)

rc.d scripts are used to start services on system startup, and to give administrators a standard way of stopping, starting and restarting the service. Ports integrate into the system rc.d framework. Details on usage can be found in the rc.d Handbook chapter. Detailed explanation of available commands are in rc(8) and rc.subr(8).

One or more rc scripts can be installed:

USE_RC_SUBR=   doormand

Scripts must be placed in the files subdirectory and a .in suffix must be added to their filename. The only difference from a base system rc.d script is that the . /etc/rc.subr line must be replaced with the . %%RC_SUBR%%, because older versions of FreeBSD do not have an /etc/rc.subr file. Standard SUB_LIST expansions are used too. Use of the %%PREFIX%%, %%LOCALBASE%%, and %%X11BASE%% expansions is strongly encouraged as well. More on SUB_LIST in the relevant section.

Prior to FreeBSD 6.1-RELEASE, integration with rcorder(8) is available by using USE_RCORDER instead of USE_RC_SUBR. However, use of this method is deprecated.

As of FreeBSD 6.1-RELEASE, local rc.d scripts (including those installed by ports) are included in the overall rcorder(8) of the base system.

Example simple rc.d script:


# PROVIDE: doormand
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
# doormand_enable (bool):   Set to NO by default.
#               Set it to YES to enable doormand.
# doormand_config (path):   Set to %%PREFIX%%/etc/doormand/doormand.cf
#               by default.

. %%RC_SUBR%%



load_rc_config $name

: ${doormand_enable="NO"}
: ${doormand_config="%%PREFIX%%/etc/doormand/doormand.cf"}

command_args="-p $pidfile -f $doormand_config"

run_rc_command "$1"

The "=" style of default variable assignment is preferable to the ":=" style here, since the former sets a default value only if the variable is unset, and the latter sets one if the variable is unset or null. A user might very well include something like

in their rc.conf.local file, and a variable substitution using ":=" would inappropriately override the user's intention.

For questions about the FreeBSD ports system, e-mail <[email protected]>.
For questions about this documentation, e-mail <[email protected]>.