This document is a WORK IN PROGRESS.
This is just a quick personal cheat sheet: treat its contents with caution!
Runit¶
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
services.
Reference(s)
- https://web.archive.org/save/https://medium.com/100-days-of-linux/setting-up-a-functional-runit-service-be75b5bc692c
- https://wiki.artixlinux.org/Main/Runit
- http://smarden.org/runit
- https://web.archive.org/web/20210519043617/https://docs.voidlinux.org/config/services/index.html
- https://docs.voidlinux.org/config/services/index.html
- https://wiki.archlinux.org/title/Runit
- https://github.com/vulk-archive/runit
$ man sv$ man runsv$ man runit$ man runit-init$ man runsvdir$ man runsvchdir
Table of contents¶
TODO¶
Runit service manager CLI tool, a helper to Runit init system. It can be installed as:
Programs¶
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 tologrotateand 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
Files¶
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 runsrunsvdir, 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 aSIGINTsignal -
/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 /etc/rc and /usr/lib/rc.
Services¶
Available services¶
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
paths are:
/etc/sv(e.g. for Void Linux)/etc/runit//etc/runit/sv(e.g. for Artix Linux)
Active services¶
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
paths are:
/service//var/service/(e.g. for Void Linux)/etc/service//run/runit/service/(e.g. for Artix Linux)
Basic service related commands¶
-
Start the
orservice_nameservice: -
Stop the
orservice_nameservice: -
Restart the
service_nameservice: -
Reload
service_nameconfiguration without stopping theservice_nameservice: -
Check the
service_nameservice status: -
Enable the
service_nameservice on system boot: -
Disable the
service_nameservice on system boot: -
Check if the
service_nameservice is enable or disable on system boot: -
Disable logs of
service_name -
Check the last logs of
service_name:
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
downlike so: -
Check if
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_namedownfile 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:
-
Enable logging:
-
Enable
service_nameand start it:
Run levels¶
By default, Runit has 2 run levels, default and single.
-
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.