Runit

From Funtoo
Revision as of 18:59, June 8, 2017 by Chry (talk | contribs) (→‎Runit)
Jump to navigation Jump to search

Runit

runit is a cross-platform Unix init scheme with service supervision, a replacement for sysvinit, and other init schemes. It can be used together with OpenRC as an alternative to sysvinit or replace OpenRC completely.

Installation

root # emerge -av sys-process/runit

Configuration over OpenRC

runit can be used as the system init. To do this, simply add init=/sbin/runit-init to the bootloader's kernel command-line and reboot. OpenRC (sysvinit) will remain installed and you go back to it at any time by reverting the change.

At this point, we are still somewhat relying on OpenRC. Because runit is very minimal, and unless you have all the boot/init scripts required, you should prefer this combo.

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

  • Stage 1:

runit starts /etc/runit/1 and waits for it to terminate. The system's one time initialization tasks are done here. /etc/runit/1 has full control over /dev/console to be able to start an emergency shell in case the one time initialization tasks fail.

  • Stage 2:

runit starts /etc/runit/2 which should not return until the system is going to halt or reboot; if it crashes, it will be restarted. Normally, /etc/runit/2 runs runsvdir.

  • Stage 3:

If runit is told to halt or reboot the system, or Stage 2 returns without errors, it terminates Stage 2 if it is running, and runs /etc/runit/3. The systems tasks to shutdown and halt or reboot are done here.

Now, let's configure Stage 1

   /etc/runit/1 - Stage 1 script file
#!/bin/sh
# system one time tasks

PATH=/sbin:/usr/sbin:/bin:/usr/bin

RUNLEVEL=S /sbin/rc sysinit
RUNLEVEL=S /sbin/rc boot
# We will add default runlevel here as well
RUNLEVEL=S /sbin/rc default

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

Now it's time to reboot...

It might look like OpenRC is running the whole thing during boot time, but once you log in and issue pstree you will see which init has started.