## Configure a service to start at boot time ##

[Author](authors.html): _name_ _[[contact]]_ _[[BSD_flavour]]_

[Reviewer](technical_reviewers.html): Cezary Morga cm@therek.net FreeBSD

[Reviewer](technical_reviewers.html): _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:

- Load the "rc.conf" configurations.
- Enable special virtual disks, like concatenated disks, Vinum Logical Volume Manager, and RAID devices.
- Enable swap device for virtual memory.
- Check file systems.
- Mount special disks or pseudo-devices.
- Mount the main / (root) disk partition.
- Set device-specific flags for terminals. (TODO: should I remove this?)
- Configure system console driver, such as setting a video mode, screen burner timeout, keyboard bell's pitch, and keyboard encoding.
- Loading initial firewall (packet filter) rules.
- Set default settings (tunables) for the kernel.
- Set the hostname.
- Turn on the network.
- Load custom packet filter rules.
- Mount /usr and /var partitions (if not already mounted).
- Initialize (seed) random devices.
- Clean up junk and /tmp files.
- Save a copy of the "dmesg" boot messages.
- Startup the syslogger daemon.
- Mount other filesystems.
- Enable swap files (if any).
- Save operating system core dump. TODO: why on OpenBSD does this happen after enabling swap?
- Create kernel and /dev device databases.
- Set default ownership and permissions on terminal devices.
- Update the "message of the day".
- Create runtime link editor directory cache. (TODO: reword that)
- Check for vi editor recovery files.
- Generate SSH host keys if needed.
- Start the SSH server.
- Start cron.

Some other tasks that may be enabled include:

- Startup the "named" DNS server.
- Start IKE key management daemon (and generate key if needed).
- Start IPsec SA failover synchronization daemon.
- Configure IPsec.
- Start the RPC program number mapper server. <!-- rpcbind or portmap -->
- Start the YP/NIS database services.
- Enable NFS services.
- Start filesystem auto-mounter. TODO: "file system" or "filesystem"? Be consistent
- Set date over network.
- Start network time server.
- Start Arla File System (AFS) cache manager. (Footnote: AFS is a distributed file system.)
- Check and enable file system quotas.
- Set kernel security level.
- Enable system accounting.
- Start various networking daemons, like routed and dhcpd.
- Enable PPP over ethernet.
- Start the "watchdog" daemon.
- Start "lpd" printer server.
- Start mail server.
- Start FTP server.
- Start inetd.
- Set audio system mixer variables.
- Start Kerberos services.
- Start Advanced Power Management (APM) monitor.
- Start mouse pointer daemon.
- Start X Display Manager.
<!-- sensord, hotplugd -->

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)

