Moving from s6-overlay v2 to s6-overlay v3
April 26, 2023 ยท View on GitHub
There are a lot of changes between version 2 of s6-overlay, which was the one used until 2021, and version 3, which was released in January 2022.
This document sums up the most important changes. As always, please refer to the latest version of the README.md file for detailed s6-overlay usage instructions.
Thanks for @alexyao2015 for the initial ideas for this document.
Immediately visible changes
- s6-overlay is now provided as a series of several tarballs, that you can pick
and choose depending on the details of how you use s6-overlay. Most people will
need two tarballs (the architecture-dependent binaries, and the architecture-independent
overlay scripts).
- These tarballs are
.tar.xzfiles: to extract them, most distributions require installing thexz-utilspackage, which is not always provided by default.
- These tarballs are
- Except when specifically built otherwise, commands and scripts provided by s6-overlay
now reside under
/command. This means several things:- The default PATH always contains
/commandas well as/usr/binand/bin. You can add directories to that PATH by declaring your ownPATHvariable in the Dockerfile. - s6-overlay commands should always be called by their short name, never by an
absolute path. You should always trust PATH to do the right thing.
- In practice: every time you used something like
/bin/s6-chmod, change it tos6-chmodinstead. That will work in every situation.
- In practice: every time you used something like
- Shebangs, which require absolute paths, are an exception, and need manual editing.
For instance,
#!/usr/bin/with-contenvshould be changed to#!/command/with-contenv.- To give you time to perform that change incrementally, s6-overlay provides
optional tarballs that install
/usr/bin/foobarsymlinks to/command/foobar.
- To give you time to perform that change incrementally, s6-overlay provides
optional tarballs that install
- The default PATH always contains
- All the user scripts need to be executable: they are now executed instead of interpreted by a shell.
- The supervision tree now resides in
/run/service, and you should not attempt to stop it when you want to exit the container; more generally you should not attempt to send control commands to the supervision tree. In particular, you should not try to run thes6-svscanctl -t /var/run/s6/servicescommand - it will not work anyway because the supervision tree has changed locations. If you need to exit a container from the inside, without your CMD dying (or without having declared a CMD), run the/run/s6/basedir/bin/haltcommand instead.- Services that were previously addressed via
/var/run/s6/services/foobarare now addressed via/run/service/foobar.
- Services that were previously addressed via
- The CMD, if any, always used to run under the container environment. This is not
the case anymore: just like supervised services, the CMD is now run with a minimal
environment by default, and you need to prepend it with
with-contenvif you want to provide it with the full container environment.
Service management-related changes
The container startup process now uses s6-rc, which has several benefits over the old method. This impacts the overlay in the following ways:
- There is a global timeout for all the services, adjustable via the
S6_CMD_WAIT_FOR_SERVICES_MAXTIMEvariable. You can disable it via setting this variable to 0. - The scripts in
/etc/cont-init.dare now run as theupcommand of the first service (a oneshot); the scripts in/etc/cont-finish.dare run as thedowncommand of the same service. This means/etc/cont-init.dis run as the first thing when the container starts, and/etc/cont-finish.dis run as the last thing when the container stops. (This does not change from the v2 behaviour.)- This means that
/etc/cont-init.dis subjected to theS6_CMD_WAIT_FOR_SERVICES_MAXTIMEtimeout. Adjust this timeout if your container initialization scripts take a long time to run.
- This means that
- The service directories in
/etc/services.dare copied to a subdirectory of/runand supervised by s6, as theupcommand of the second service. This means they're started after/etc/cont-init.dis run, and they are not stopped until the container stops. Services declared in/etc/services.dare still running when/etc/cont-finish.dis run; they are stopped afterwards. - Rather than running their services in
/etc/cont-init.d,/etc/services.dand/etc/cont-finish.d, users can now add s6-rc source definitions for them, so they will be run independently by the service manager. The old way is still supported, and will continue to be, but we encourage users to switch to the new way.- This has the advantage of supporting both oneshots (scripts that do one thing and exit) and longruns (daemons that are supervised with s6), and dependencies can be declared between services for super flexible ordering; you can also add more complex service pipelines for multi-step log processing.
- The drawback is that it requires following the
s6-rc source format,
which is not immediately intuitive. Please read the documentation attentively
if you want to convert your services to that format. As a quickstart, what you
need to know immediately is:
- You need a
typefile in the directory, saying whether the service is aoneshotor alongrun. - The source definition directory for a longrun looks a lot like a service
directory: it has a
runscript, possibly afinishscript, etc. - The source definition directory for a oneshot is different. It
needs an
upfile, but don't write your script in it. Instead, put your script in another executable file, in a place of your choice (for instance/etc/s6-overlay/scripts/foobar, and just put/etc/s6-overlay/scripts/foobarin yourupfile. Be aware thatupis not a shell script, and will not honor shebangs; for the details, look forweird syntaxin the README file. - To get your service foo properly started at container boot time, you need
to add it to the
userbundle:touch /etc/s6-overlay/s6-rc.d/user/contents.d/foo. Also, to ensure it's started at the proper time, you should make it depend onbase:mkdir /etc/s6-overlay/s6-rc.d/foo/dependencies.d && touch /etc/s6-overlay/s6-rc.d/foo/dependencies.d/base.
- You need a
- Services are run from their own, temporary, current working directory, instead
of
WORKDIR; scripts should now use absolute paths instead of paths relative toWORKDIR. The CMD, if any, is still run inWORKDIR.
Other changes
- Socklog has been replaced by a
syslogd-overlaytarball, provided by s6-overlay. The tarball expands into a series of s6-rc services implementing a small syslogd emulation, using a combination of the news6-socklogbinary and as6-logservice with a complex logging script that dispatches logs the same way syslogd would.