BSDwiki/ Configure a service to start at boot time

Configure a service to start at boot time

Author: name contact BSD flavour

Reviewer: Cezary Morga cm@therek.net FreeBSD

Reviewer: name contact BSD flavour


Concept

Recognize that the BSD boot process does not use runlevels. Be able to configure essential services to start at boot time to minimize the impact of a system reboot.

TODO: PUT THIS NEXT TO RELATED CONCEPTS

Introduction

The BSDs all run the /etc/rc system startup script. It is ran by /sbin/init (known as the "parent of all processes") before it initializes the terminals and local logins.

Note that the BSDs do not have System V-style runlevels, such as found on Linux, where different startup scripts are available for networking, X11 workstation, server, etc. (On systems with multiple runlevels, these are normally done by using symlinks in the specific runlevel directories pointing to the desired startup scripts.)

TODO: should this mention single-user mode here? Point to it.

The /etc/rc scripts vary on each system, but all basically do the same steps:

Some other tasks that may be enabled include:

TODO: more to list

On OpenBSD, the /etc/rc script is mostly self-contained, while on DragonFly, FreeBSD, and NetBSD, the /etc/rc script runs many individual startup scripts, commonly found in the /etc/rc.d/ directory. Details about about manually using rc.d scripts as used on NetBSD, FreeBSD and DragonFly are covered in section Use an rc(8) script to determine if a service is running and start, restart or stop it as required.

The BSDs primarily use /etc/rc.conf to configure what is started up.

On NetBSD, FreeBSD, and DragonFly, the rc.conf defaults are stored in the /etc/defaults/rc.conf file. The settings in /etc/rc.conf override the defaults. Do not edit the defaults so upgrades are easier.

The configurations are done by setting a shell variable so be careful to use proper Bourne shell syntax such as no spaces around equal signs and making sure quotes are ended.

OpenBSD Configuration

On OpenBSD, /etc/rc.conf contains the system defaults. It is suggested to keep custom settings in /etc/rc.conf.local which overrides the defaults.

On OpenBSD, the shell variables can be set to "NO" to disable that feature or set to the command-line arguments (flags). For example, here is an example of some enabled settings on OpenBSD:

sshd_flags=""
sendmail_flags="-L sm-mta -C/etc/mail/localhost.cf -bd -q30m"
inetd=YES
check_quotas=YES

And here are some disabled settings on OpenBSD:

spamd_flags=NO
spamlogd_flags=""
nfsd_flags="-tun 4"
nfs_server=NO

Note in the above example, even though spamlogd_flags is not set to NO, it is disabled because spamd_flags=NO. And even though nfsd_flags has command-line arguments, it also disabled via nfs_server=NO. TODO: do formatting here

TODO: add separate sections for other BSDs here

FreeBSD Configuration

To enable FreeBSD rc.d scripts so they are used at boot time, the individual scripts need to be enabled. The variable name with its default setting can be seen by running the rc.d script with "rcvar" as the argument; for example:

$ /etc/rc.d/inetd rcvar
# inetd
$inetd_enable=NO

To enable the feature (to start at boot for example), set that variable in your /etc/rc.conf (or /etc/rc.conf.local) file (do not use string/dollar sign in front):

inetd_enable=YES

By default, FreeBSD's startup will use rcorder(1) to scan the /etc/rc.d/ and /usr/local/etc/rc.d/ directories. The "rcorder" tool will look at special tags that identify and order the rc.d scripts.

On FreeBSD, the /etc/rc.d/localpkg rc.d script will run the /usr/local/etc/rc.d/ scripts using old style semantics (don't contain the "rcorder" tags). They must be named with ".sh" on the end and must be executable. It will run files starting with a digit first which can be used for ordering if you don't use the rc.d system.

TODO: cover ordering using rc.d system very briefly

TODO: cover "force" and "fast" command prefixes? Where should this be covered?

TODO: FreeBSD and DragonFly also use /etc/rc.conf.local by default but NetBSD does not. TODO: /etc/rc.conf.d/ directory is also available but don't over in this intro book?

TODO: make sure this is not redundant with other sections

Examples

Practice Exercises

More information

rc.conf(5) (or rc.conf(8) on OpenBSD), rc(8), inetd(8)