man openrc

OpenRC

NAME

openrc: the init system of Mwa Linux

DESCRIPTION

OpenRC starts the services at boot, in the order their dependencies require. It stops them at shutdown.

On Mwa Linux, openrc-init is PID 1. There is no sysvinit. supervise-daemon can restart a service that dies.

Commands that change the system run as root, through doas.

FILES

/etc/rc.conf
global settings, with comments
/etc/conf.d/
settings of each service
/etc/init.d/
service scripts
/etc/runlevels/
enabled services, one directory per runlevel
/var/log/rc.log
boot output, if rc_logger is on

SERVICES

Start, stop, restart, show the state:

$ doas rc-service dhcpcd start
$ doas rc-service dhcpcd stop
$ doas rc-service dhcpcd restart
$ rc-service dhcpcd status

Start a service at every boot, or stop doing it:

$ doas rc-update add iwd default
$ doas rc-update del iwd default

Listing needs no root:

$ rc-update show -v
$ rc-status
$ rc-status -s

RUNLEVELS

A runlevel is a set of services: a directory in /etc/runlevels. Mwa Linux starts three, in this order:

sysinit
udevd, udev-trigger
boot
nftables, sysklogd
default
dhcpcd, agetty.tty1 … agetty.tty6, agetty.ttyS0

The firewall starts in boot, before the network. It blocks incoming connections. No service listens on the network after installation.

iwd (Wi-Fi) and dbus are installed but not enabled. For Wi-Fi: doas rc-update add iwd default.

Create a runlevel, switch to it, then go back:

$ doas install -d /etc/runlevels/offline
$ doas openrc offline
$ doas openrc default

To boot straight into it, add softlevel=offline to the kernel command line.

DEPENDENCIES

Each script says what it needs in its depend() function. To change that without editing the script, use /etc/conf.d/<service>:

rc_need="dbus"

rc_need: start dbus first, and stop this service if dbus stops. rc_use: start it first only if it is enabled. rc_after: order only.

SUPERVISION

With supervise-daemon, OpenRC watches the process and restarts it if it dies. Turn it on in /etc/conf.d/<service>:

supervisor="supervise-daemon"
respawn_delay=2
respawn_max=5

The program must stay in the foreground. Check its options: often -f or --foreground.

LOGS

OpenRC writes nothing to disk by default. To keep the boot output, in /etc/rc.conf:

rc_logger="YES"

It goes to /var/log/rc.log. The logs of the services go to sysklogd, in /var/log.

WRITING A SERVICE

A service is a shell script in /etc/init.d:

#!/sbin/openrc-run
description="my daemon"
command="/usr/bin/mydaemon"
command_args="--foreground"
supervisor="supervise-daemon"

depend() {
	need localmount
	after firewall
}
$ doas chmod +x /etc/init.d/mydaemon
$ doas rc-update add mydaemon default
$ doas rc-service mydaemon start

TROUBLESHOOTING

A service shows crashed: the process died but OpenRC still thinks it runs. Reset its state, then start it:

$ doas rc-service mydaemon zap
$ doas rc-service mydaemon start

doas openrc brings the system back to its runlevel: it starts what is missing and stops what was started by hand. doas openrc -n does not stop anything.

SEE ALSO

man pages: openrc, openrc-run, openrc-init, rc-service, rc-update, rc-status, supervise-daemon

bunny, OpenRC user guide

made with <3 by dogmwa