s6 is a process supervision suite that also provides tools for service management (s6-rc) and system initialization/shutdown (s6-linux-init).

General overview

s6 software is all designed to be very modular and can be mixed and matched with other things. However, s6 software is also designed to work well with one another. In Artix, we take full advantage of what s6 offers and use all of the available tools to provide an /sbin/init, PID1, process supervisor suite, and service manager for users.

s6-linux-init is what actually initiates your system. It mounts a tmpfs onto /run and copies the /etc/s6/current/run-image directory into /run. /sbin/init then execs into the s6-svscan program (provided by the s6 package) which functions as your PID1 for the lifetime of the machine. Once this is done, the stage 1 part of init is finished. In addition to being PID1, s6-svscan is also the root of your process supervision tree. It monitors every service found and appropriately spawns an s6-supervise for every service.

Additionally, during bootup the rc.init script in the /etc/s6/current/scripts directory gets executed. s6 itself does not do service management, but only process supervision. In rc.init, the actual service manager, s6-rc is started. From that point, we launch the default runlevel defined by s6-rc and begin the desired services.

On shutdown, every service in s6-rc is brought down, followed by killing all s6-supervise processes and other processes, then unmounting everything, and finally killing s6-svscan.

Note: s6-linux-init on artix is compiled with the option to print messages to /dev/console. By default, this is tty1. You can change /dev/console to another location using a kernel parameter (see your bootloader's configuration) if you'd like.

Recovery: s6-linux-init always provides a getty service on tty12 that you can use for recovery purposes (in case s6-rc crashes, etc.). As long as the system correctly boots, it will be there.

Installation

Install the s6-base package.

Installation of services

s6 service packages are named package_name-s6 and, when installed, will be available in /etc/s6/sv.

Programs

The s6 software suite comes with many different binaries, but in general you only need to directly interact with the one-stop-shop frontend command, s6, which routes to the appropriate layer. It has many subcommands:

  • s6 live - Controls service startup and dependency management. Can be shortened to s6 l. It shells out to commands in the s6-rc service manager package, among which:
    • s6-rc - starts and stops services to change machine state, taking dependencies into account, and allows querying which services are up or down.
    • s6-rc-db - a tool for analyzing a compiled service database.
  • s6 process - manages individual processes, without handling dependencies. Can be shortened to s6 proc or s6 p. Shells out to s6-svc and s6-svstat in the s6 (process supervisor package). Unlike latter, they don't need you to explicitly specify where the s6-svscan PID 1 is listening (in Artix's case, /run/service).
  • s6 set - manages the default bundle, allowing you to disable or enable services on boot. Shells out to the s6-rc-set-* binaries.
  • s6 repository - manages the source definition stores. Can be shortened to s6 repo or s6 r. Shells out to the s6-rc-repo-* binaries.

Files

Most of the files associated with the s6 software packages are installed in the /etc/s6 directory.

  • /etc/s6/current - the base directory for s6-linux-init
  • /etc/s6/current/scripts - various startup/shutdown scripts executed by s6-linux-init
  • /etc/s6/config - conf files for specific s6-rc services
  • /etc/s6/rc - where compiled databases are stored; the current live database is always symlinked to /etc/s6/rc/compiled
  • /etc/s6/rc.local - file for executing arbitrary shell commands on bootup (any shell scripts in /etc/local.d suffixed with *.start are executed on bootup and those with *.stop are executed on shutdown)
  • /etc/s6/skel - contains the default startup/shutdown scripts that come with artix linux
  • /etc/s6/sv - default directory for script packages from Artix
  • /etc/s6/adminsv - directory for custom user services as well as script packages from Artix that allow for editing
  • /etc/s6/repo - the location of service sets managed by s6-rc repo commands

Basic usage

A key concept to using s6 is to understand the notion of "bundles". You can take their namesake literally. They are handled by s6's service management layer, and a bundle is any collection of longruns, oneshots, and even other bundles. These are quite similar to openrc's runlevels and are used in similar ways in Artix. The package, s6-scripts, which contains essential startup oneshots and daemons for an Artix system internally uses many different bundles for convenience, but for users the main bundle they should concern themselves with is the default bundle. This is started by the s6-rc service and in users can manage its contents with the s6 set command.

Note: There is a bundle within default called boot. This is a collection of startup/shutdown boot oneshots and daemons deemed essential for a working system. These are mostly provided by the s6-scripts package with some optional dependencies that install themselves into the appropriate directory.

Also note that the dependency management layer ensures that when service foo is started, all of its dependencies (if they are not already up) are automatically started, without the user needing to explicitly specify them. Here are some handy commands.

  • Stop a service/bundle: # s6 live start service_name
  • Start a service/bundle: # s6 live stop service_name
  • Restart a longrun: # s6 process restart longrun_name
  • Send a signal to a longrun: # s6 process kill [ -s SIGNAL ] longrun_name (e.g. s6 p kill -s HUP foo-srv to reload most services' configuration).
  • List services in the database and whether they're active: # s6 live status (-E to list all services, including essential ones)
  • List only active services: s6-rc -a list
  • List all services and bundles in the database: s6-rc-db list all
  • Check the status of a longrun # s6 process status longrun_name

Commands that apply to longrun services have a few caveats: they don't work with oneshot services, and you may need to append -srv to the service name to control a logged service.

Updating the default bundle

You can use the s6 program to enable and disable services that start by default.

  • Enable a service # s6 set enable service_name
  • Disable a service # s6 set disable service_name
  • See a status list of live services # s6 live status

In order to make any changes you made persistent, you need to run # s6 set commit and # s6 live install after you are done.

If you made any changes to the service definitions (added, removed or replaced services), you need to run # s6 repo sync before committing and installing.

Source directory structure

s6-rc has three types of services: longrun, oneshot, and bundle. Most *-s6 packages are longrun services (AKA daemons). Oneshot services do exactly what their name implies: execute once on bootup and optionally on shutdown. Bundles are simply a collection of longruns, oneshots, and even other bundles. Every source directory will have a mandatory type file that contains a single line defining what type the service is. Longrun services must contain a file called run, oneshots must contain a file called up, and bundles contain a subdirectory named contents.d.

In Artix, a typical service script comes with two different parts: the daemon itself and the logger daemon that uses the s6-log tool. The scripts for the actual service foo will be installed in the /etc/s6/sv directory as foo-srv. Additionally, a small logger daemon for that specific service will be installed in foo-log. foo-log will catch any output from foo-srv and save it in /var/log/foo directory. The s6-log logger daemon is run as the s6log user and group. To give a user permission to view logs, just add him to the s6log group. s6-log does log rotation for you and has many different configurable options.

When interacting with s6-rc, the name of foo doesn't change (i.e. you still do # s6-rc -u change foo). This starts both foo-srv and foo-log and handles any of the dependencies for you.

This is a tree of a longrun directory structure (aka /etc/s6/sv/foo-srv). In many scripts, only producer-for, type, and run exist.

 foo-srv
 ├── dependencies.d (optional subdir containing names of dependencies)
 ├── notification-fd (optional)
 ├── producer-for (required for foo-log)
 ├── run
 └── type

A tree for a logger daemon longrun (aka /etc/s6/sv/foo-log) looks like this.

 foo-log
 ├── consumer-for
 ├── notification-fd
 ├── pipeline-line
 ├── run
 └── type

See also