Manage s6-overlay setup with s6-cli

󰃭 2024-12-06

I developed a small cli in golang to ease creating, validating and documenting services that s6 supervises.

Usage

You do not need to install anything, just execute the binary via docker

docker run -it --rm hakindazz/s6-cli help
COMMANDS:
   create, c   create a service
   remove, rm  remove a service
   lint, l     lint directories and files
   mermaid, m  document s6 service dependencies in mermaid syntax
   help, h     Shows a list of commands or help for one command

Create a service with s6-cli

docker run -it --rm -v ./:/etc/s6-overlay hakindazz/s6-cli create oneshot init-dependencies

Here is the file / directory structure it creates:

/etc/s6-overlay/s6-rc.d
├── init-dependencies
│   ├── dependencies.d
│   │    ├── base
│   │    └── svc-php-fpm
│   ├── type
│   └── up
└── scripts
        └── init-dependencies
  • The base dependency is added by s6-cli
  • Adding base as default dependency tells s6-rc to only start a service when all the base services are ready, and it prevents race conditions

Use s6-cli in your CI

docker run -it --rm -v .:/etc/s6-overlay hakindazz/s6-cli lint

It will tell you when it does not find any issue

s6-cli: lint found no issues

Or list the findings so you can fix them before you deploy.

s6-cli: lint found issues with services in /etc/s6-overlay/s6-rc.d
- svc-lint-me
  - type file for "svc-lint-me" does not end with a newline
  - invalid type in svc-lint-me/type file specified

Document your setup with mermaid

You can use the mermaid command to output the dependency graph between the services:

docker run -it --rm -v .:/etc/s6-overlay hakindazz/s6-cli mermaid
```mermaid
graph TD;
    user --> init-dependencies
    user --> init-migrations
    user --> svc-nginx
    init-migrations --> init-directories
    svc-php-fpm --> init-directories
    svc-nginx --> init-nginx
    svc-nginx --> svc-php-fpm

Which will result in this mermaid

graph TD; user --> init-dependencies user --> init-migrations user --> svc-nginx init-migrations --> init-directories svc-php-fpm --> init-directories svc-nginx --> init-nginx svc-nginx --> svc-php-fpm

Enter your instance's address


More posts like this

Mastering Multi-Process Containers: Running PHP Applications with s6-overlay

󰃭 2025-03-26 | #ci #devops #docker #s6-overlay

The Dockerized Development Setup

Containerization has completely changed how we build and deploy PHP applications. With Docker, you can make sure that your production environment behaves just like your local setup, which means fewer surprises when you go live.

In this post, we’re diving into running Symfony in a container that runs multiple processes using s6-overlay. We’ll explain why having more than one process in a container can be important, how this idea is different from Docker’s usual “one process per container” rule, and how s6-overlay makes it easier to run everything together.

Continue reading 


Build your own s6-overlay base image

󰃭 2024-08-19 | #devops #docker #s6-overlay

S6-overlay is a container-focused process manager that offers end-to-end management of the container’s lifecycle, from initialization to graceful shutdown.

To make use of s6-overlay we need to add the binaries to our container by adding, extracting and then moving them to the directory where they are expected.

ADD https://github.com/just-containers/s6-overlay/releases/download/3.2.0.0/s6-overlay-noarch.tar.xz /tmp  
ADD https://github.com/just-containers/s6-overlay/releases/download/3.2.0.0/s6-overlay-x86_64.tar.xz /tmp

Update dependencies

When adding the s6-overlay sources to in a Dockerfile we want to make sure that we get notified when a new version is available, so we can always be up-to-date with all our libraries. This can be achieved by adding a section to our Renovate or Dependabot config, a rule to match

Continue reading 