Back to Article Listing

FreeBSD rc - daemon startup


There is a LOT to know about rc -- command scripts for auto-reboot and daemon startup. And, there is already lots of documentation. But, here is a quick & dirty primer. Then you'll need to 'man rc' and 'man rc.conf' to catch up.

There are generally two types of applications that you would want to start up automatically when the computer boots. Some may do an action and shutdown but most will run as a daemon.

  1. system-userland application that comes as part of the OS like SSH
  2. add-on application like Apache or Courier-IMAP.

The add-on applications are treated a little differently than those that come with the OS. But, in general, you need to put a little entry in a file that is read at boot time.

  • entry : some_application_flag=YES
  • file : /etc/rc.conf

Keep in mind

  • For ALL apps; you need a corresponding YES|NO switch in /etc/rc.conf (which you may have to create and write)

    I use YES|NO as the simplest example. Switches will be what each specified program expects.

  • For add-on apps; you will also need a start-up script in /usr/local/etc/rc.d/.

    If you installed from ports or packages, the port will probably include one if it is a daemon app. If not, roll your own!

While the concepts for both types of applications are similar, you have to know where to find the exact "YES|NO rc.conf switch" that each program expects; in order to correctly trigger start up.

  • system-userland: defaults are kept in /etc/defaults/rc.conf

    (like pf_enable="YES" or sshd_enable="YES") As it states in the header of this file, do NOT change defaults. Over-ride them with entries in /etc/rc.conf.

  • add-on apps: defaults are kept in their respective startup scripts

    (like apache_enable="YES" or courier_imap_imapdssl_enable="YES")

You should check out all the default switches that are available to you in /etc/defaults/rc.conf, there is some cool stuff there.

Now, we are going to look at tracking down the specifics needed for an add-on app. You can check on the correct spelling that rc is expecting by reading the applications start up script -or- by running the startup script and ask it what they are expecting. If an application is to be expected to run at boot, it must expose the magic words that trigger it. These are contained in the "rcvar".

Below is an example that runs the startup script with the 'please check the rc variable' switch. In our example there is no such switch in rc.conf yet, it returns NO.

$ /usr/local/etc/rc.d/ rcvar
    # courier_imap_imapdssl

There are other switches besides rcvar, start and stop come to mind. You can find out the rest by reading the script -or- if you have already set the rcvar.. passing a bad switch and it will spit out the usage, like this:

$ /usr/local/etc/rc.d/ xxx
    /usr/local/etc/rc.d/ unknown directive 'xxx'.
    Usage: /usr/local/etc/rc.d/ [fast|force|one](start stop restart rcvar  status poll)

So now, when you read "..add a switch to rc.conf..", you know what that means.

Copyright © 20050110 genoverly
(db datestamp: 20070821)

Copyright © 2003-2015 genoverly