User:Capezotte/s6 on Gentoo

This aims to be a guide on how to set up a Gentoo system with a full s6 stack (s6-linux-init, s6-svscan+s6-supervise, s6-rc), and ultimately allowing you to replace sysvinit.

Included in the LEGO set

 * s6-svscan and s6-supervise (and associated tools) are the workhorse of system management. They start services, ensure they are reachable and there's only one instance of them, and restarts them automatically if they crash.
 * s6-linux-init performs the bare minimum of system initialization needed for s6-svscan and handles shutdown.
 * s6-rc enhances s6-svscan with the ability to start services only when they are ready and to run oneshots (scripts do one thing on system startup/shutdown).

Getting started
You'll want to emerge sys-apps/s6 (s6-svscan+s6-supervise), sys-apps/s6-rc and sys-apps/s6-linux-init. Avoid emerging the latter with USE="sysvinit-utils" so you can fall back to sysvinit+OpenRC if things go awry.

Service definitions
Creating services with s6-rc will feel familiar if you've already used runit, but it also has support for one-shot scripts, which allow us to handle stage 1 (core system initialization) and stage 2 (starting actual long-running services) with the same tool.

With s6-rc, services are folders with at least one file called type, whose contents are one of these three strings:
 * longrun: what we usually think of being services: programs that run for the lifetime of the machine, providing some sort of functionality (e.g. device management, usually udev). If you choose this type, there must also be an executable file called run. It's usually a script that performs necessary setup and then execs into the program, which must be in foreground mode (otherwise, s6 will lose track of it).
 * oneshot: a small script performing setup before or after a service is started. For instance, mounting filesystems (i. e. calling mount -a), or calling udev to recognize currently plugged devices (i. e. udevadm trigger). If you choose this type, you must provide an up file, which is an execline script. For very simple scripts, it will be exactly like shell, but you can't use single quotes. If you aren't willing to learn it, no worries -- just write the script in whichever language you like the most and write its filename to up.
 * bundle: a set of longruns, oneshots or even other bundles (at least one, which in this case makes the bundle effectively an alias/"provides"). You write the name of the each included longrun, oneshot or sub-bundle, one per line, to a file named contents, which is mandatory.

This is just a very simplistic introduction. For the full description, read the docs.

Core system initialization is basically mounting the virtual filesystems ( /dev, /proc, /sys ), reading settings from the file system ( sysctl, hostname ) and creating the utmp files. For reference, you can see how Artix implements core s6 services. I'll admit I copy pasted a lot of them for this setup:


 * mount-cgroups
 * mount-devfs
 * mount-filesystems
 * mount-net
 * mount-procfs
 * mount-sysfs
 * mount-tmpfs
 * sysctl
 * cleanup (more specifically the utmp related portions).
 * hostname

I'll admit I've copied and pasted these services (though eventually changed the bundles they're part of).