Modular Computers the manual GitHub

rc

rc: start, stop and enable services.

Synopsis

rc
rc name start|stop|restart|status|enable|disable
rc name action
rc boot

Description

A service is a program that runs in the background (a daemon), started at boot or by hand. Each is a Lua script in /etc/rc.d, named for it, run in an environment of its own where name is its name. It sets, as OpenRC’s scripts do:

command
The program, as a path.
command_args
Its arguments: a list, or a string split on spaces.
description
What it is.
output_log
A file its output and errors are added to; /dev/null when not given.

From those, rc gives it the actions below. A function the script defines by one of their names (start, stop, status) is used instead, and any other function it defines is an action too: rc name action calls it (its return value, a number, is the exit status). For example:

description = "remote shell daemon"
command = "/bin/mcsshd"
command_args = {"-p", "22"}
function reload()
  require("sys").kill(tonumber(io.open("/run/" .. name .. ".pid"):read("l")), "SIGHUP")
end

With no arguments, rc lists the services: each one’s name, whether it’s enabled, and whether it’s running.

Actions

start
Runs it in a session of its own, with no terminal (so no ^C at a terminal reaches it) and its input from /dev/null, and keeps its process id in /run/name.pid.
stop
Sends it SIGTERM, and SIGKILL if it hasn’t ended within 5 seconds.
restart
Stops it, then starts it.
status
Says whether it’s running.
enable, disable
Sets name_enable=YES (or NO) in /etc/rc.conf: whether it starts at boot.
boot
Starts every service enabled in /etc/rc.conf, in its order. /etc/rc runs it at boot: the kernel runs that script with sh before the console’s shell starts (the rc= boot option names another).

Exit status

0 on success; status 3 when it isn’t running; 1 for a bad argument, a service that doesn’t exist, or one that can’t be started.

Files

/etc/rc
The boot’s script.
/etc/rc.conf
Which services start at boot.
/etc/rc.d/name
A service.
/run/name.pid
A running service’s process id (/run is in memory, mounted by /etc/rc).

Examples

rc mcsshd enable
rc mcsshd start
rc mcsshd status

Notes

Linux has several: sysvinit’s scripts in /etc/init.d are shell scripts that take start and stop themselves; OpenRC’s set settings and may define their own functions (as these do, with OpenRC’s names, in Lua: mcos’s scripting language); systemd has units. rc.conf’s name_enable is FreeBSD’s, as is /etc/rc.d. Services start in rc.conf’s order, with no dependencies between them.

See also

sh(1), kill(1), ps(1)