runit is a compact init scheme and service supervision suite for Unix-like systems that starts the machine in three distinct stages and keeps every configured service running under a dedicated supervisor process. In Linux system initialization it is one of the main alternatives to systemd, used as the default init on Void Linux and offered on distributions such as Artix and antiX, and it is equally common as a pure supervisor inside containers.
Written by Gerrit Pape and modeled on the daemontools design by Daniel J. Bernstein, runit favors small, auditable programs that each do one job. Services are described by plain shell scripts in directories, not by declarative unit files, and reliability comes from supervision: a crashed daemon is restarted within about a second without any external monitoring.
How runit boots a system in three stages
When runit is the init system, the kernel starts runit as process ID 1, and that program does little more than run three scripts in order. This separation keeps PID 1 tiny, which matters because a crash of PID 1 causes a kernel panic.
| Stage | Script | Responsibility | Completion |
|---|---|---|---|
| Stage 1 | /etc/runit/1 | One-time setup: mount filesystems, set hostname, load modules | Runs once and exits |
| Stage 2 | /etc/runit/2 | Starts runsvdir, which supervises all services | Runs for the system lifetime |
| Stage 3 | /etc/runit/3 | Shutdown tasks: stop services, sync and unmount | Ends with halt or reboot |
Stage 2 should never exit during normal operation. If it does, runit proceeds to stage 3 and shuts down. Shutdown and reboot are requested through the runit-init command (usually linked as init), which signals PID 1 to leave stage 2 cleanly. A failure in stage 1 drops the system into an emergency shell, giving the administrator a chance to repair it.
Service supervision with runsvdir, runsv and sv
Supervision in runit relies on a process hierarchy of small daemons. runsvdir watches a service directory, typically /var/service or /etc/service, and starts one runsv process for every subdirectory it finds; each runsv in turn runs and monitors one service.
A service is defined by a directory containing an executable run script that must start the daemon in the foreground. When the daemon exits, runsv notices immediately through the parent-child relationship and starts it again. An optional finish script runs after each exit, and a log subdirectory defines a second supervised process that receives the service’s standard output through a pipe.
| Program | Role | Key detail |
|---|---|---|
| runit | PID 1, executes the three stages | Minimal code by design |
| runsvdir | Starts one runsv per service directory | Rescans the directory about every five seconds |
| runsv | Supervises a single service | Restarts it on exit, exposes control files |
| sv | Command-line control and status tool | Sends commands through a control pipe |
| svlogd | Logging daemon for service output | Rotates logs by size and count |
| chpst | Changes process state before exec | Sets user, limits and environment |
Administrators interact with services through sv commands such as sv up, sv down, sv restart and sv status. Enabling a service means creating a symbolic link from its definition directory into the supervised directory; removing the link disables it.
How runit compares with systemd, OpenRC and SysVinit
runit occupies a deliberate middle ground: it offers true process supervision like systemd but keeps the small footprint and script-based configuration associated with traditional init systems. The comparison below covers the attributes that usually drive the choice.
| Attribute | runit | systemd | OpenRC | SysVinit |
|---|---|---|---|---|
| Service definition | Shell run scripts | Declarative unit files | Shell scripts with dependencies | Shell init scripts |
| Automatic restart | Built in for every service | Configurable per unit | Optional supervisor | None by default |
| Dependency handling | Implicit, by retrying | Explicit ordering and requirements | Explicit dependencies | Numbered script order |
| Parallel startup | Yes, all services at once | Yes, dependency-driven | Optional | No |
| Socket activation | No | Yes | No | No |
| Logging | svlogd per service | Central journal | syslog | syslog |
runit has no dependency graph. If a service needs another one, its run script checks the condition, for instance with sv check postgresql, and exits when it is not met; runsv then retries. This approach is simple and robust but makes startup ordering less explicit than in systemd, and features such as timers, socket activation and cgroup resource control are absent or must come from other tools.
Writing and managing runit services in practice
A good run script is short and ends by replacing itself with the daemon through exec, so that runsv supervises the daemon directly rather than an intermediate shell. Redirecting standard error to standard output with exec 2>&1 lets the logging service capture both streams.
- Run in the foreground: pass the daemon its no-fork flag, such as
-Dfor sshd or-g 'daemon off;'for Nginx. - Drop privileges with chpst, for example
exec chpst -u www-data mydaemon, instead of starting as root. - Add a log service with
exec svlogd -tt /var/log/myserviceto obtain timestamped, rotated logs. - Use a down file in the service directory to keep a service enabled but stopped at boot.
The following decision table helps judge where runit fits best.
| Scenario | Fit | Reason |
|---|---|---|
| Minimal or embedded system | Strong | Small code size and fast boot |
| Multi-process container | Strong | Reliable supervision without a full init |
| Desktop with complex session management | Weaker | Many components assume systemd interfaces |
| Services needing socket activation or timers | Weaker | Requires external tools such as cron |
Limitations and common mistakes with runit
Most runit problems stem from misunderstanding the foreground requirement or from expecting systemd-style features. The table lists recurring symptoms and their remedies.
| Symptom | Likely cause | Fix |
|---|---|---|
| Service restarts every second | Daemon forks into the background | Use the foreground flag |
| sv status shows down after linking | run script not executable | Set the executable bit |
| No log output appears | Missing log service or stderr redirect | Add log/run and exec 2>&1 |
| Service starts before its database | No dependency check | Test with sv check and exit on failure |
| sv cannot find the service | Wrong SVDIR or missing symlink | Link into the active service directory |
Because runsv restarts failing services indefinitely, a misconfigured daemon can loop quietly and consume resources; checking sv status uptime values reveals services that never stay up for more than a second. Administrators moving from systemd should also expect that some software ships only unit files, so a run script must be written by hand.
Understanding it simply
When a Linux computer starts, one program must take charge of launching everything else and keeping it running. runit is a small, simple program for that job.
It works in three steps: prepare the machine, run the services, and shut down neatly. While the computer runs, runit acts like a watchful caretaker: if a service stops unexpectedly, it switches that service back on within about a second, without anyone needing to notice the problem first.
Applied in practice
A small company runs a Docker container that must host both a web application and a background job worker. Containers normally run one process, so the team installs runit inside the image and makes runsvdir /etc/service the container’s main command, with two service directories, one for the web server and one for the worker.
During a traffic spike, the worker crashes because of a memory error in a third-party library. Within a second, runsv restarts the worker automatically, and svlogd records the crash with a timestamp in its rotated log. The web application keeps answering requests throughout, and engineers later read the logs, patch the library and redeploy, having avoided an outage that would otherwise have required a manual container restart.