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 tologrotate
and 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 aSIGINT
signal -
/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,sv
will 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_name
service: -
Stop the
orservice_name
service: -
Restart the
service_name
service: -
Reload
service_name
configuration without stopping theservice_name
service: -
Check the
service_name
service status: -
Enable the
service_name
service on system boot: -
Disable the
service_name
service on system boot: -
Check if the
service_name
service 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
down
like so: -
Check if
service_name
is 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
down
file 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_name
and 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/runsvdir
and 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.