Linux® uses the SysV init system, whereas FreeBSD uses the traditional BSD-style init(8). Under the BSD-style init(8) there are no run-levels and no /etc/inittab, instead startup is controlled by the rc(8) utility. The /etc/rc script reads /etc/defaults/rc.conf and /etc/rc.conf to determine which services are to be started. The specified services are then started by running the corresponding service initialization scripts located in /etc/rc.d/ and /usr/local/etc/rc.d/. These scripts are similar to the scripts located in /etc/init.d/ on Linux systems.
Why are there two locations for service initialization scripts? The scripts found in /etc/rc.d/ are for applications that are part of the “base” system. (cron(8), sshd(8), syslog(3), and others.) The scripts in /usr/local/etc/rc.d/ are for user-installed applications such as Apache, Squid, etc. What is the difference between the “base” system and user-installed applications? FreeBSD is developed as a complete operating system. In other words, the kernel, system libraries, and userland utilities (such as ls(1), cat(1), cp(1), etc.) are developed and released together as one. This is what is referred to as the “base” system. The user-installed applications are applications that are not part of the “base” system, such as Apache, X11, Mozilla Firefox, etc. These user-installed applications are generally installed using FreeBSD's Packages and Ports Collection. In order to keep them separate from the “base” system, user-installed applications are normally installed under /usr/local/. Therefore the user-installed binaries reside in /usr/local/bin/, configuration files are in /usr/local/etc/, and so on. |
Services are enabled by specifying ServiceName_enable="YES" in /etc/rc.conf (rc.conf(5)). Take a look at /etc/defaults/rc.conf for the system defaults, these default settings are overridden by settings in /etc/rc.conf. Also, when installing additional applications be sure to review the documentation to determine how to enable any associated services.
The following snippet from /etc/rc.conf enables sshd(8) and Apache 2.2. It also specifies that Apache should be started with SSL.
# enable SSHD sshd_enable="YES" # enable Apache with SSL apache22_enable="YES" apache22_flags="-DSSL"
Once a service has been enabled in /etc/rc.conf, the service can be started from the command line (without rebooting the system):
# /etc/rc.d/sshd start
If a service has not been enabled it can be started from the command line using forcestart
:
# /etc/rc.d/sshd forcestart