Skip to content

Lesson 3 of 9 · 24m

Services, rc.d, and Safe Operating System Upgrades

Manage daemons through rc.conf and service scripts, understand boot ordering, and apply freebsd-update in a sequence that survives reboots.

FreeBSD service management is old-fashioned in the best sense: explicit shell scripts, declarative enablement, dependency ordering, and logs you can read without a query language. It is also unforgiving when administrators improvise. Learn the rc system once and upgrades stop being coin flips.

Enable, inspect, and control services explicitly

The standard lifecycle is simple:

sysrc sshd_enable=YES
service sshd status
service sshd restart
service -e
service -R

service -e lists enabled services in dependency order; service -R restarts enabled services that need it. /etc/rc.conf is the primary contract, while /etc/rc.conf.local and files under /etc/rc.conf.d/ can organize host-specific or automation-generated overrides.

Read rc scripts before inventing one

Service scripts live in /etc/rc.d for base services and /usr/local/etc/rc.d for packages. A minimal custom script starts with the rc.subr contract:

#!/bin/sh
# PROVIDE: mineworker
# REQUIRE: NETWORKING
# KEYWORD: shutdown

. /etc/rc.subr
name=mineworker
rcvar=mineworker_enable
command=/usr/local/sbin/mineworker
pidfile=/var/run/mineworker.pid

load_rc_config $name
run_rc_command "$1"

The PROVIDE and REQUIRE lines are ordering metadata, not comments for humans. If a daemon needs network, filesystem, or another service, say so. Race conditions at boot are often dependency declarations that never happened.

freebsd-update is a sequence, not a button

Patch-level updates use a repeatable flow:

freebsd-update fetch
freebsd-update install
shutdown -r now
freebsd-update install

The second install matters after kernel replacement because userland updates may depend on the new kernel being active. Release upgrades are heavier:

freebsd-update -r 14.2-RELEASE upgrade
freebsd-update install
shutdown -r now
freebsd-update install
pkg upgrade

Do not blindly copy this into production without snapshots, console access, and a rollback plan. The command sequence is simple; recovering a remote host with no out-of-band console is not.

Merge configuration changes deliberately

Major upgrades can conflict with modified files in /etc. freebsd-update may invoke merge handling; read differences instead of accepting either side wholesale. /etc/rc.conf, /etc/sysctl.conf, /etc/pf.conf, and /etc/ssh/sshd_config are where unattended upgrades become outages. Keep these files small, explicit, and under configuration management so reconstruction is possible.

Boot output is operational evidence

dmesg, /var/run/dmesg.boot, /var/log/messages, and service-specific logs tell different parts of the story. If a service died at boot but starts manually, suspect dependency ordering, unavailable network, missing filesystems, or a jail/network interface timing problem. If it never starts manually, start with configuration validation and the service script exit status.

Field notes

  • Never place daemon startup hacks in cron when an rc script can express dependencies and shutdown behavior.
  • service name onestatus and related one* commands can inspect services not enabled at boot.
  • freebsd-update does not upgrade packages; run pkg upgrade separately after OS userland is settled.
  • Console access matters most on the day network or SSH configuration is wrong. Verify it before the upgrade window.

Was this lesson helpful?

Sign in to rate