s6 is a process supervision suite that also provides tools for service management (s6-rc) and PID 1 (s6-linux-init).

Installation

Install the s6 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 a small subset of them.

  • s6-rc - the main program for controlling and managing services
  • s6-rc-bundle - adding and deleting bundles without having to recompile the live database
  • s6-rc-db - a tool for analyzing a compiled service database

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; it contains /etc/s6/current/scripts which has various startup/shutdown scripts
  • /etc/s6/rc - where compiled databases are stored; the current database is symlinked to /etc/s6/rc/compiled
  • /etc/s6/rc.local - file for executing arbitrary shell commands on bootup; /etc/rc.local is executed instead if it exists
  • /etc/s6/s6.conf - a global s6 config file for setting certain values for startup s6-rc services
  • /etc/s6/skel - cointains various startup/shutdown scripts for s6-linux-init; symlinked to /etc/s6/current/scripts for package management tracking
  • /etc/s6/sv - the directory containing s6-rc source definitions

Basic usage

By default, s6-rc will start a bundle named "default" if it exists. To create and add services to the bundle, you can do the following: # s6-rc-bundle add default service1 service2 service3 etc. Note that due to the database format s6-rc uses, you must first delete a bundle added with the s6-rc-bundle command and then remake it if you want to modify it. So just run # s6-rc-bundle delete default before another s6-rc-bundle add command. Also note that s6-rc manages dependencies so it is not neccesary to manually start all needed dependencies. When service foo is started, all of its dependencies (if they are not already up) are automatically started. Here are some handy commands.

  • Stop a service/bundle # s6-rc -d change service_name
  • Start a service/bundle # s6-rc -u change service_name
  • List all active services # s6-rc -a list
  • List all services/bundles in the database # s6-rc-db list all

Because s6-rc uses a database format, all *-s6 packages in Artix execute a libalpm hook ensuring that all newly installed scripts are immediately available in a new database. This consists of 3 main steps. First, it compiles a new database with a unique name generated by the date command with s6-rc-compile. Then, it executes s6-rc-update to update the live database to the newly compiled database. Finally, it atomically updates the symlink to /etc/s6/rc/compiled so on the next boot, the system executes the newest database. Additionally, there is logic to preserve bundles created with the s6-rc-bundle command and recreate them in the new database (otherwise, users would have to manually recreate them).

Note that this will leave behind old database directories in /etc/s6/rc. Feel free to remove them if they are not needed. If you wish to add your own services to /etc/s6/sv, it is probably best to simply execute the libalpm hook manually # sh /usr/share/libalpm/scripts/s6-rc-db-update-hook so all of the above boilerplate is handled for you.

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 manadatory 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 must contain a file called contents.

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

 servicedir
 ├── conf (optional)
 ├── dependencies (optional)
 ├── notification-fd (optional)
 ├── run
 └── type

See also