The OpenBSD BASED Challenge Day 7

By Root BSD

I took control of my daemons with rcctl(8)!

image

All *nix like operating systems have a system services or daemons manager. In most GNU/Linux systems it's systemctl, sv, rc-service or something similar. On FreeBSD it's service, and on OpenBSD it's rcctl(8).

On OpenBSD services are basically shell scripts that are stored in the /etc/rc.d/ directory. The main configuration files are /etc/rc.conf and /etc/rc.conf.local for user-specific settings. The /etc/rc file is a system startup script run by init on autoboot or after single-user startup.

Some features of rcctl(8) need to be ran using doas(1) or as root. Others don't like checking the status of a daemon. For example,

rcctl -df check unbound doing _rc_parse_conf doing _rc_quirks unbound_flags empty, using default >-c /var/unbound/etc/unbound.conf< doing _rc_parse_conf /var/run/rc.d/unbound doing _rc_quirks unbound doing rc_check (ok)

This will give me basic information on what the unbound daemon is doing. The command after the -df option is called an action argument. Removing the -df option will just give you the basic status of the daemon, usually either (ok) or (failed).

The main commands for rcctl(8), are start, stop, reload, restart, enable and disable. Those are pretty self-explanatory. Start and stop are temporary, enable/disable are persistent across boots. As mentioned previous the -df option will output more information as the commands are ran, sort of like a verbose option.

doas rcctl -df restart tor doas rcctl reload sndiod

The get command displays the value of the service or daemon variable. For example,

rcctl get sndiod
sndiod_class=daemon sndiod_flags= sndiod_logger= sndiod_rtable=0 sndiod_timeout=30 sndiod_user=root

You can include a variable to search for information, like this,

rcctl get sndiod user root

The variables that can be used are class, flags, logger, status, timeout or user. You can set the get command to β€œall” to get a full listing of all the service values and variables on the system.

rcctl get all | grep "NO"

Will output a list of all the services whose flags are set to β€œNO”. The getdef command is like get but returns all the default values of the daemons. The ls command can be used with ls arguments or lsargs, for example

doas rcctl ls on

This will list all the system services and daemons that are currently enabled. The ls arguments are all, failed, off, on, rogue, started or stopped. The argument rogue is interesting, it lists daemons which are disabled, but are still currently running.

The order command is useful when a new package daemon is started and it needs to be ran before other already enabled daemons, placing it at the beginning of pkg_scripts.

Last is the set command, which can set the status variable of a service or daemon to on or off. The set command is also used to configure flags and options for specific daemons. For example,

doas rcctl set apmd status on doas rcctl set apmd flags -A this writes β€œapmd_flags=-A” to the /etc/rc.conf.local file

This sets the status of the apm(8) daemon to on, the sets the flags to -A for automatic power management.

doas rcctl set sndiod flags -e s24le4lsb -z 400 -s default -m play,mon -s mon

That enables daemon specific settings for sndiod(8), the encoding is set to it's highest possible value, the audio device block size to 400 frames (120Hz), the exposed sub-devices to default, the mode to playback and monitoring, and another monitoring sub-device. These flags are detailed in the sndiod(8) manpage. Once again this command writes to the /etc/rc.conf.local, so it is not necessary to manually edit that file.

The rcctl(8) utility is a simple and effective tool for managing system services and daemons in OpenBSD. You can also write your own daemons, place them in the /etc/rc.d directory and start/enable them with rcctl(8). Everything is K.I.S.S., simple, elegant and straightforward. That's the OpenBSD way. I hope you learned something new. I sure did. May your UNIX beard grow long and your knowledge increase, and as always, happy hacking in OpenBSD!

image

Configuring the apm(8) (power management) daemon to automatic, then enabling it to start every boot.