runit, replacement for init

runit, a Unix init scheme with service supervision written by Gerrit Pape, is a complete replacement for SysVinit. Its key benefits include improved boot speed and ease of use. In the time that it takes you to read this article, you could move from init to runit.

Moving from init to runit on Debian
Of course, runit's precise ease of use depends on the distro you're using. You'll find it either easy or very easy. If you use Debian then you just need to install the runit, runit-services, and runit-run packages. Even easier, just add the following line to /etc/apt/sources.list:

deb unstable main non-free contrib

Then run:

sudo apt-get update
sudo apt-get install runit runit-services runit-run

Debian will handle all of the conversion from using init to using runit for you. However — don't reboot yet! Before you do that you're going to have to tell the kernel to use runit instead of init. Edit /boot/grub/menu.lst, find the line that loads your Linux kernel, and make an addition to its end. For instance, on my system, I changed

kernel /boot/vmlinuz-2.4.27-2-386 root=/dev/hda1 ro


kernel /boot/vmlinuz-2.4.27-2-386 root=/dev/hda1 ro init=/sbin/runit-init

Now you can reboot and use runit for the first time by typing:

sudo runit-init 6

Moving from init to runit on OpenBSD29 and FreeBSD44


Step 1: The three stages
runit looks for the three stages implementing the system's booting, running and shutdown in /etc/runit/1, /etc/runit/2 and /etc/runit/3 respectively. Create the scripts now:

 # mkdir -p /etc/runit

OpenBSD 2.9:
 # cp -p /package/admin/runit/etc/openbsd/[123] /etc/runit/

FreeBSD 4.4:
 # cp -p /package/admin/runit/etc/freebsd/[123] /etc/runit/

Remove the svscanboot startup from /etc/rc.local by deleting the line csh -cf '/command/svscanboot &' (this normally is the last one); runit will start runsvdir in stage 2 after running rc.local in stage 1.

 # vi /etc/rc.local

Step 2: The runit programsThe runit programs must reside on the root partition, install them into /sbin:

 # install -m0500 /package/admin/runit/command/runit* /sbin/

Step 3: The getties
At least one getty must run in stage 2 so that you are able to login. To have it run on the virtual console no 5, create the getty-5 service directory:

 # mkdir -p /etc/sv/getty-5

OpenBSD 2.9:
 # cp -p /package/admin/runit/etc/openbsd/getty-ttyC4/run /etc/sv/getty-5/
 # cp -p /package/admin/runit/etc/openbsd/getty-ttyC4/finish /etc/sv/getty-5/

FreeBSD 4.4:
 # cp -p /package/admin/runit/etc/freebsd/getty-ttyv4/run /etc/sv/getty-5/
 # cp -p /package/admin/runit/etc/freebsd/getty-ttyv4/finish /etc/sv/getty-5/

and tell runsvdir about the getty-5 service:

 # mkdir -p /var/service
 # ln -s /etc/sv/getty-5 /var/service/

Start runit's stage 2 for testing:

 # /etc/runit/2 &

And check that the getty is running.

Step 4: Replace the /sbin/init binaryBefore replacing the init binary, make sure that you are able to boot your system alternatively, e.g. with a boot floppy, to restore the former /sbin/init if anything goes wrong.
Make a backup copy of the current /sbin/init program and replace it with /sbin/runit-init:

 # cp -p /sbin/init /sbin/init.bsd
 # install /sbin/runit-init /sbin/init

Boot your system with runit for the first time:

 # reboot

Watch the console output while runit boots up the system. Switch to the virtual console 5 (CTRL-ALT-F5) when stage 2 is reached, a getty should run there, you are able to login.

Use init 6 to reboot and init 0 to halt a system that runs runit. This will cause runit to enter stage 3 which runs /sbin/reboot or /sbin/halt as last command.

To report success:

 # ( uname -a ; cat /etc/runit/[123] ) |mail

Step 5: Service migration
The goal is to migrate all services from /etc/rc.* scheme to the runit service supervision design; take a look at these run scripts for popular services. The migration can be done smoothly. By default runit runs the /etc/rc scripts in stage 1 as a one time task, so the services are started automatically:

 # system one time tasks

 /bin/sh /etc/rc autoboot

 touch /etc/runit/stopit
 chmod 0 /etc/runit/stopit

To migrate a service, create a service directory, disable the service if it is running, disable the service in /etc/rc.conf or remove the service startup from the /etc/rc.* scripts and tell runsvdir about the new service.
After some tests on OpenBSD39 and FreeBSD61, i will update this post to replace runit on these versions.

till then ciao :]



About this entry