(redirected from Runit.Runit)

runit is a suite of tools which provides an init (PID 1) as well as daemontools-compatible process supervision framework, along with utilites which streamline creation and maintenance of services.

Installation

Install the runit package.

Installation of services

runit service packages are named package_name-runit and, when installed, will be available in /etc/runit/sv.

Programs

Runit has several programs, but usually you will only interact directly with one program only.

  • 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 logrotate and the need to stop your services to rotate logs.
  • runsvchdir - changes service levels (runlevels, 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 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 SIGINT signal
  • /etc/runit/runsvdir/* - Runlevels
  • /etc/runit/sv/* - directory containing subdirectories of available service files
  • /run/runit/service - always symlinked to active runlevel, 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.

Basic usage

Unlike other distros using runit, Artix doesn’t store its service directory in /var/service or /service, but in /run/runit/service instead.

  • Enable service (in runlevel default)# ln -s /etc/runit/sv/service_name /run/runit/service
  • Disable service # touch /run/runit/service/service_name/down
  • Stop immediately # sv down service_name or # sv stop service_name
  • Start (if not running) # sv up service_name or # sv restart service_name
  • Restart # sv restart service_name
  • Reload # sv restart service_name
  • Status check # sv status service_name
  • Switch runlevels (this will stop all services that are currently running and will start all services in the new runlevel) # runsvchdir runlevel

Runlevel

By default, runit has 2 runlevels, default and single. You can make your own runlevels just by creating a new folder in /etc/runit/runsvdir/ and symlinking your desired service to that runlevel.

 ln -s /etc/runit/sv/service /etc/runit/runsvdir/runlevel@@

Service directory structure

This is a tree of a complete service directory structure (aka /etc/runit/sv/servicedir), in some run scripts, typically only run will be available as usually it's the only file needed.

 servicedir
 ├── run (755)
 ├── check (755)
 ├── conf (644)
 ├── finish (755)
 └── log (directory)
     ├── config (644)
     └── run (755)

A runit (or any daemontools-compatible) service directory contains at least one executable file, named run, which runs process in the foreground.

This means that:

  • The run file must be a symlink to the service executable, or a script that eventually exec's into it.
  • The service executable must not run in the background, otherwise runit will lose track of its state. If necessary, the run script should pass flags to the service executable that prevent this behavior (such as enabling debug mode).

The service directory may also contain executables like finish and check. finish will be executed when a service is stopped, and check will be executed (if exists) by sv check or sv status.

Some run scripts can source variables and additional commands from a user-supplied conf file (which should be created in the service directory, and is not executable). Usually, a run shell script that supports a conf file has the line [ -r ./conf ] && . ./conf.

If a service directory contains another directory named log, the output of the run process in the service directory will be piped to the input of the run process in the log directory. If the log service uses svlogd, it may be configured by using the file config. How svlogd can be configured is explained in the svlogd(1) manpage.

Service dependencies

Some services may depend on other services. For example, NetworkManager depends on dbus. To ensure that required dependencies are satisfied, check the service's run file. For example, for NetworkManager:

 # /etc/runit/sv/NetworkManager/run
 sv check dbus >/dev/null || exit 1

This means you have to enable dbus for NetworkManager to start.

See also