From 9eda003e19a6e01edd951ad84dd50a4804129d73 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 4 May 2023 23:52:12 +0000 Subject: [PATCH] Fix terminal management with latest s6-l-i, version: 3.1.5.0 Also add S6_CMD_USE_TERMINAL to make use of the new fix. Signed-off-by: Laurent Bercot --- README.md | 13 +++++++++---- conf/defaults.mk | 4 ++-- conf/versions | 4 ++-- .../etc/s6-linux-init/skel/rc.init | 7 +++++++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 666bf38..dfa4cee 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Build the following Dockerfile and try it out: ``` # Use your favorite image FROM ubuntu -ARG S6_OVERLAY_VERSION=3.1.4.1 +ARG S6_OVERLAY_VERSION=3.1.5.0 RUN apt-get update && apt-get install -y nginx xz-utils RUN echo "daemon off;" >> /etc/nginx/nginx.conf @@ -847,7 +847,12 @@ with the rest of the shutdown. the shutdown procedure when all the processes have received a TERM signal, for them to die before sending a `KILL` signal to make *sure* they're dead. * `S6_LOGGING_SCRIPT` (default = "n20 s1000000 T"): This env decides what to log and how, by default every line will prepend with ISO8601, rotated when the current logging file reaches 1mb and archived, at most, with 20 files. -* `S6_CMD_ARG0` (default = not set): Value of this env var will be prepended to any `CMD` args passed by docker. Use it if you are migrting an existing image to a s6-overlay and want to make it a drop-in replacement, then setting this variable to a value of previously used ENTRYPOINT will improve compatibility with the way image is used. +* `S6_CMD_ARG0` (default = not set): Value of this env var will be prepended to any `CMD` args passed by docker. Use it if you are migrating an existing image to s6-overlay and want to make it a drop-in replacement: setting this variable to the value of a previously used ENTRYPOINT will help you transition. +* `S6_CMD_USE_TERMINAL` (default = 0): Set this value to **1** if you have a CMD that needs a terminal for its output +(typically when you're running your container with `docker run -it`), and you have set `S6_LOGGING` to a nonzero value. +This setting will make your CMD actually output to your terminal; the drawback is that its output will not be logged. +By default (when this variable is **0** or not set), the stdout and stderr of your CMD are logged when `S6_LOGGING` is nonzero, +which means they go to a pipe even if you're running it in an interactive terminal. * `S6_FIX_ATTRS_HIDDEN` (default = 0): Controls how `fix-attrs.d` scripts process files and directories. * **`0`**: Hidden files and directories are excluded. * **`1`**: All files and directories are processed. @@ -863,7 +868,7 @@ Note that this value also includes the time setting up legacy container initiali and that it is taken into account even if you are not running a CMD. In other words: no matter whether you're running a CMD or not, if you have scripts in `/etc/cont-init.d` that take a long time to run, you should set this variable to either 0, or a value high enough so that your scripts have time to finish without s6-overlay interrupting them and diagnosing an error. -* `S6_READ_ONLY_ROOT` (default = 0): When running in a container whose root filesystem is read-only, set this env to **1** to inform init stage 2 that it should copy user-provided initialization scripts from `/etc` to `/var/run/s6/etc` before it attempts to change permissions, etc. See [Read-Only Root Filesystem](#read-only-root-filesystem) for more information. +* `S6_READ_ONLY_ROOT` (default = 0): When running in a container whose root filesystem is read-only, set this env to **1** to inform init stage 2 that it should copy user-provided initialization scripts from `/etc` to `/run/s6/etc` before it attempts to change permissions, etc. See [Read-Only Root Filesystem](#read-only-root-filesystem) for more information. * `S6_SYNC_DISKS` (default = 0): Set this env to **1** to inform init stage 3 that it should attempt to sync filesystems before stopping the container. Note: this will likely sync all filesystems on the host. * `S6_STAGE2_HOOK` (default = none): If this variable exists, its contents will be interpreted as a shell excerpt that will be run in the early stage 2, @@ -941,7 +946,7 @@ RUN cd /tmp && sha256sum -c *.sha256 ### `USER` directive -As of version 3.1.4.1, s6-overlay has limited support for running as a user other than `root`: +As of version 3.1.5.0, s6-overlay has limited support for running as a user other than `root`: * Tools like `fix-attrs` and `logutil-service` are unlikely to work (they rely on being able to change UIDs). diff --git a/conf/defaults.mk b/conf/defaults.mk index 572e97c..aecf0b3 100644 --- a/conf/defaults.mk +++ b/conf/defaults.mk @@ -3,7 +3,7 @@ # e.g.: make SHEBANGDIR=/usr/bin VERSION=3.1.4.0 # The version of the software being built. -VERSION := 3.1.4.2 +VERSION := 3.1.5.0 # Where stuff is going to be built. Change for out-of-tree builds. OUTPUT := output @@ -21,7 +21,7 @@ TOOLCHAIN_PATH := # When fetching one from the web, what version we want. # Only a few versions are available, don't change blindly. -TOOLCHAIN_VERSION := 12.2.0 +TOOLCHAIN_VERSION := 13.1.0 # For fetching toolchains: the download command. # Change to curl -O if you don't have wget. diff --git a/conf/versions b/conf/versions index 23fa5d7..b81b09d 100644 --- a/conf/versions +++ b/conf/versions @@ -18,8 +18,8 @@ S6_VERSION=v2.11.3.2 # S6_RC_VERSION=58f93f6c710cc88acfa721a45efc1f64dfc557df S6_RC_VERSION=v0.5.4.1 -# S6_LINUX_INIT_VERSION=b5ed0d1ef886d3c12345c22e6e42aa5fca272bb4 -S6_LINUX_INIT_VERSION=v1.1.1.0 +# S6_LINUX_INIT_VERSION=3be1f17208a1e3d48c1c0607bff50402bc45ceb3 +S6_LINUX_INIT_VERSION=v1.1.1.1 # S6_PORTABLE_UTILS_VERSION=a80a1304ff86b8cf493265696d517aea2cf7a703 S6_PORTABLE_UTILS_VERSION=v2.3.0.2 diff --git a/layout/rootfs-overlay/package/admin/s6-overlay-@VERSION@/etc/s6-linux-init/skel/rc.init b/layout/rootfs-overlay/package/admin/s6-overlay-@VERSION@/etc/s6-linux-init/skel/rc.init index 0374d01..038968a 100755 --- a/layout/rootfs-overlay/package/admin/s6-overlay-@VERSION@/etc/s6-linux-init/skel/rc.init +++ b/layout/rootfs-overlay/package/admin/s6-overlay-@VERSION@/etc/s6-linux-init/skel/rc.init @@ -1,5 +1,9 @@ #!/bin/sh -e +# This is stage 2, the part of the initialization that is run once +# the s6 supervision tree has been set up. This is where all the +# services are brought up, and the CMD, if any, is run. + trap : INT # guard against ^C as much as possible prog=/run/s6/basedir/scripts/rc.init @@ -58,6 +62,9 @@ if test "$#" -gt 0 ; then cd `s6-cat < /run/s6/workdir` set +e arg0=`printcontenv S6_CMD_ARG0` + if b=`printcontenv S6_CMD_USE_TERMINAL` && eltest "$b" =~ '^[[:digit:]]+$' -a "$b" -gt 0 && b=`tty` ; then + arg0="redirfd -w 1 $b fdmove -c 2 1 $arg0" + fi if b=`printcontenv S6_CMD_RECEIVE_SIGNALS` && eltest "$b" =~ '^[[:digit:]]+$' -a "$b" -gt 0 ; then $arg0 "$@" & cmdpid="$!"