This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!
Runit is a suite of tools which provides an init (
PID 1) as well as daemon tools compatible
process supervision framework, along with utilities which streamline creation and maintenance of
$ man sv
$ man runsv
$ man runit
$ man runit-init
$ man runsvdir
$ man runsvchdir
Table of contents¶
- Run levels
Runit service manager CLI tool, a helper to Runit init system. It can be installed as:
Runit is composed of several programs:
sv: used for controlling services, getting status of services, and dependency checking.
chpst: control of a process environment, including memory caps, limits on cores, data segments, environments, user/group privileges, and more.
runsv: supervises a process, and optionally a log service for that process.
svlogd: a simple but powerful logger, includes auto rotation based on different methods (time, size, etc), post processing, pattern matching, and socket (remote logging) options. Say goodbye to
logrotateand the need to stop your services to rotate logs.
runsvchdir: changes service levels (run levels, see below)
runsvdir: starts a supervision tree
runit-init: PID 1, does almost nothing besides being the init
There are several files that will be installed by Runit.
/etc/runit/1: stage 1, system’s one-time initialization tasks
/etc/runit/2: stage 2, Normally runs
runsvdir, should not return until the system is going to halt or reboot.
/etc/runit/3: stage 3, system’s shutdown tasks
/etc/runit/ctrlaltdel: Runit will execute this when receiving a
/etc/runit/runsvdir/*: Run levels
/etc/runit/sv/*: directory containing sub directories of available service files
/run/runit/service: always symlinked to active run level,
svwill search for running service here
However, since Runit itself depends on
runit-rc, there will be several extra
rc files installed,
most contained in
Most distros using Runit won't store available services in the same directory. So let's define a
$AVAILABLE_RUNIT_SERVICE_DIR environment variable holding the path to that directory. Most common
/etc/sv(e.g. for Void Linux)
/etc/runit/sv(e.g. for Artix Linux)
Most distros using Runit won't store active services in the same directory. So let's define a
$ACTIVE_RUNIT_SERVICE_DIR environment variable holding the path to that directory. Most common
/var/service/(e.g. for Void Linux)
/run/runit/service/(e.g. for Artix Linux)
Basic service related commands¶
service_nameconfiguration without stopping the
service_nameservice on system boot:
service_nameservice on system boot:
Check if the
service_nameservice is enable or disable on system boot:
Disable logs of
Check the last logs of
Advanced service related commands¶
List available services:
Prevent a service from starting at boot (i.e. disable it), while allowing Runit to manage it, by creating a file named
service_nameis working correctly when started by the service supervisor, run it once before fully enabling it:If everything works, remove the
# touch $AVAILABLE_RUNIT_SERVICE_DIR/service_name/down # ln -s $AVAILABLE_RUNIT_SERVICE_DIR/service_name $ACTIVE_RUNIT_SERVICE_DIR # sv once service_name
downfile to enable the service.
Create a service¶
Create the active service directory:
Create a down file in the service directory, until the setup is completed:
Create a run file in the service directory:
service_nameand start it:
By default, Runit has 2 run levels,
Switch run levels (this will stop all services that are currently running and will start all services in the new run level):
Make your own run level (e.g.
myrunlvl) by creating a new folder in
/etc/runit/runsvdirand symlinking your desired service to that run level (⚠️ this example is specific to Artix Linux ⚠️ ):
If this cheat sheet has been useful to you, then please consider leaving a star here.