G. Pape

runit - a UNIX init scheme with service supervision


How to install runit
Upgrading from previous versions of runit

Benefits
How to replace init
How to use runit with current init
How to use dietlibc

Runlevels
Service dependencies
A collection of run scripts

The runit program
The runit-init program

The runsvdir program
The runsvchdir program

The runsv program
The runsvstat program
The runsvctrl program

The svlogd program

The svwaitdown program
The svwaitup program
The utmpset program


runit is a daemontools alike replacement for sysvinit and other init schemes. runit runs on GNU/Linux, OpenBSD, FreeBSD, Mac OSX, and can easily be adapted to other unix operating systems. If runit runs for you on any other operating system or Linux distribution, please let me know.

Warning: Replacing sysvinit or init can cause the system's boot to fail. Make sure you are able to recover and repair your system, for example if you run a boot loader, it should be able to pass init=/bin/sh to the kernel.


runit is discussed on the <supervision@list.skarnet.org> mailing list. To subscribe send an empty email to <supervision-subscribe@list.skarnet.org>.
The command runit is intended to run as Unix process no 1, it is automatically started by the runit-init /sbin/init-replacement if this is started by the kernel.

runit performs the system's booting, running and shutting down in three stages:

These are working examples for Debian woody: /etc/runit/1, /etc/runit/2, /etc/runit/3.

The command runit-init is intended to replace /sbin/init. sysvinit's command shutdown will keep working. On *BSD systems use init 0 for system halt and init 6 for reboot. Runlevels are handled through the runsvdir and runsvchdir programs. Service dependencies are rudimentarily handled through the svwaitup and svwaitdown programs, see Dependencies and runlevels for an example.

runit is optimized for reliability and small size. The amount of code in process no 1 should be minimal.


runit in use: I replaced sysvinit with runit on several server systems and a laptop running Debian/GNU Linux sarge, woody and potato, and did not encounter any problems. Of course also the smarden.org content server is running with runit as process no 1, here is an example:
 # strings /proc/1/exe |grep Id
 $Id: runit.c,v 1.7 2002/02/13 09:59:52 pape Exp $
 # uptime
  13:16:19 up 219 days, 23:35,  1 user,  load average: 0.00, 0.00, 0.00
 # ps axuw |head -n20
 USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
 root         1  0.0  0.0    20   16 ?        S     2002   0:07 runit
 root         2  0.0  0.0     0    0 ?        SW    2002   0:00 [keventd]
 root         3  0.0  0.0     0    0 ?        SWN   2002   0:00 [ksoftirqd_CPU0]
 root         4  0.0  0.0     0    0 ?        SW    2002   2:47 [kswapd]
 root         5  0.0  0.0     0    0 ?        SW    2002   0:08 [bdflush]
 root         6  0.0  0.0     0    0 ?        SW    2002   0:13 [kupdated]
 root       168  0.0  0.0  1652  208 ?        S     2002   0:00 /usr/sbin/cron
 root       174  0.0  0.0    36   24 ?        S     2002   0:00 runsvdir /var/service log: ....................................................................................................
 root       176  0.0  0.0    20   20 ?        S     2002   0:00 runsv qmail-send
 root       177  0.0  0.0    20   20 ?        S     2002   0:00 runsv getty-5
 root       178  0.0  0.0    20   20 ?        S     2002   0:00 runsv getty-4
 root       179  0.0  0.0    20   20 ?        S     2002   0:00 runsv getty-3
 root       180  0.0  0.0    20   20 ?        S     2002   0:00 runsv getty-2
 root       182  0.0  0.0    20   20 ?        S     2002   0:00 runsv socklog-unix
 root       183  0.0  0.0  1256   28 tty5     S     2002   0:00 getty 38400 tty5 linux
 root       184  0.0  0.0  1256   28 tty3     S     2002   0:00 getty 38400 tty3 linux
 root       185  0.0  0.0    20   20 ?        S     2002   0:00 runsv socklog-klog
 root       186  0.0  0.0    20   20 ?        S     2002   0:00 runsv ssh
 root       187  0.0  0.0  1256   28 tty4     S     2002   0:00 getty 38400 tty4 linux
 # pstree
 runit-+-bdflush
       |-cron
       |-gcache
       |-keventd
       |-ksoftirqd_CPU0
       |-kswapd
       |-kupdated
       `-runsvdir-+-runsv-+-multilog
                  |       `-qmail-send-+-qmail-clean
                  |                    |-qmail-lspawn
                  |                    `-qmail-rspawn
                  |-4*[runsv---getty]
                  |-2*[runsv-+-multilog]
                  |          `-socklog]
                  |-runsv-+-multilog
                  |       `-sshd-+-sshd---sshd---bash
                  |              `-sshd---sshd---bash---bash---pstree
                  |-runsv---clockspeed
                  |-runsv-+-dnscache
                  |       `-multilog
                  |-runsv---apache-ssl-+-9*[apache-ssl]
                  |                    |-gcache
                  |                    `-4*[multilog]
                  |-5*[runsv-+-multilog]
                  |          `-tcpserver]
                  |-3*[runsv-+-multilog]
                  |          `-tinydns]
                  |-runsv---uncat
                  |-2*[runsv-+-multilog]
                  |          `-tcpsvd]
                  |-runsv-+-multilog
                  |       `-tcpserver---smtpfront-qmail
                  |-runsv
                  `-runsv-+-svlogd
                          `-tcpsvd---smtpfront-qmail
This is from a more busy system:
 # strings /proc/1/exe |grep Id
 $Id: runit.c,v 1.7 2002/02/13 09:59:52 pape Exp $
 # uptime
  13:21:22 up 114 days, 35 min,  3 users,  load average: 0.77, 0.56, 0.54
 # ps axuw |head
 USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
 root         1  0.0  0.0    20    4 ?        S    Feb11   0:04 runit
 root         2  0.0  0.0     0    0 ?        SW   Feb11   0:01 [keventd]
 root         3  0.0  0.0     0    0 ?        SW   Feb11   0:25 [kapmd]
 root         4  0.0  0.0     0    0 ?        SWN  Feb11   1:02 [ksoftirqd_CPU0]
 root         5  0.0  0.0     0    0 ?        SW   Feb11  11:57 [kswapd]
 root         6  0.0  0.0     0    0 ?        SW   Feb11   7:58 [bdflush]
 root         7  0.0  0.0     0    0 ?        SW   Feb11  13:49 [kupdated]
 root        57  0.0  0.0     0    0 ?        SW   Feb11   0:00 [msp3410 [auto]]
 root       191  0.0  0.0    36   24 ?        S    Feb11   2:42 runsvdir /var/service log: ....................................

See How to install runit for installing runit and How to replace init for smoothly escaping from sysvinit.
If runit on linux is compiled and linked with dietlibc it yields in a statically linked runit binary of 8.5k size and this ps axuw output on my system:
  USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
  root         1  0.0  0.0    20   16 ?        S     2002   0:02 runit
I recommend doing this; for instructions, see How to use dietlibc.
See http://smarden.org/runit/ for recent informations.
Related links:
Gerrit Pape <pape@smarden.org>
$Id$