Browse Source

Add features for the linuxserver image

- S6_STAGE2_HOOK for the early stage2 hook
- S6_VERBOSITY for variable s6-rc verbosity
- user2 bundle for late services

Signed-off-by: Laurent Bercot <[email protected]>
Laurent Bercot 3 years ago
parent
commit
28c3519efe

+ 28 - 0
README.md

@@ -497,16 +497,29 @@ When the container is started, the operations are performed in this order:
 dependencies. Services can be oneshots (initialization
 tasks) or longruns (daemons that will run throughout the container's lifetime).
 - (legacy) Longrun services in `/etc/services.d` are started.
+- Services in the `user2` bundle with the correct dependency are started.
+(Most people don't need to use this; if you are not sure, stick to the `user` bundle.)
 
 When the container is stopped, either because the admin sent a stop command or
 because the CMD exited, the operations are performed in the reverse order:
 
+- Services in the `user2` bundle with the correct dependency are stopped.
 - (legacy) Longrun services in `/etc/services.d` are stopped.
 - All s6-rc services are stopped, in an order defined by dependencies. For
 oneshots, that means that the `down` script in the source definition directory
 is executed; that's how s6-rc can perform finalization tasks.
 - (legacy) One shot finalization scripts in `/etc/cont-finish.d` are run sequentially.
 
+The point of the `user2` bundle is to allow user services declared in it to
+start *after* the `/etc/services.d` ones; but in order to do so, every service
+in `user2` needs to declare a dependency to `legacy-services`. In other words,
+for a service `foobar` to start late, you need to:
+- Define it in `/etc/s6-overlay/s6-rc.d/foobar` like any other s6-rc service.
+- Add an `/etc/s6-overlay/s6-rc.d/foobar/dependencies.d/legacy-services` file
+- Add an `/etc/s6-overlay/s6-rc.d/user2/contents.d/foobar` file.
+
+That will ensure that `foobar` will start _after_ everything in `/etc/services.d`.
+
 ### Writing an optional finish script
 
 By default, services created in `/etc/services.d` will automatically restart.
@@ -812,6 +825,21 @@ if you have scripts in `/etc/cont-init.d` that take a long time to run, you shou
 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_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,
+before services are started. This can be used, for instance, to dynamically
+patch the service database at run-time right before it is compiled and run.
+The wrong value can prevent your container from running or endanger your
+security, so only use this if you know exactly what you are doing. When in
+doubt, leave this variable undefined.
+* `S6_VERBOSITY` (default = 2): controls the verbosity of s6-rc, and potentially
+other tools, at container start and stop time. The default, 2, is normally verbose:
+it will list the service start and stop operations. You can make the container quieter
+by decreasing this number: 1 will only print warnings and errors, and 0 will only
+print errors. You can also make the container _more_ verbose, i.e. print tracing and
+debug information, by increasing this number up to 5, but the output will quickly
+become _very_ noisy, and most people shouldn't need this.
+
 
 ### syslog
 

+ 1 - 1
conf/defaults.mk

@@ -3,7 +3,7 @@
 # e.g.: make SHEBANGDIR=/usr/bin VERSION=3.1.1.0
 
 # The version of the software being built.
-VERSION := 3.1.1.0
+VERSION := 3.1.2.0
 
 # Where stuff is going to be built. Change for out-of-tree builds.
 OUTPUT := output

+ 0 - 0
layout/rootfs-overlay/etc/s6-overlay/s6-rc.d/user2/contents.d/.empty


+ 1 - 0
layout/rootfs-overlay/etc/s6-overlay/s6-rc.d/user2/type

@@ -0,0 +1 @@
+bundle

+ 26 - 4
layout/rootfs-overlay/package/admin/s6-overlay-@VERSION@/etc/s6-linux-init/skel/rc.init

@@ -1,18 +1,40 @@
 #!/bin/sh -e
 
+prog=/run/s6/basedir/scripts/rc.init
 top="$1" ; shift
 
 if test -d /run/s6/container_environment ; then
   s6-chmod 0755 /run/s6/container_environment
 fi
 
+if v=`printcontenv S6_VERBOSITY` && s6-test "$v" =~ '^[[:digit:]]*$' ; then
+  if test "$v" -gt 0 ; then
+    cv=$((v - 1))
+  else
+    cv=0
+  fi
+else
+  v=2
+  cv=1
+fi
+
+if hook=`printcontenv S6_STAGE2_HOOK` && test -n "$hook" ; then
+  set +e
+  $hook
+  r=$?
+  set -e
+  if test "$r" -gt 0 && test "$v" -gt 0 ; then
+    echo "$prog: warning: hook $hook exited $r" 1>&2
+  fi
+if
+
 if profile=`printcontenv S6_RUNTIME_PROFILE` ; then
   etc="/etc/cont-profile.d/$profile"
 else
   etc=/etc
 fi
 
-s6-rc-compile -v1 /run/s6/db "$etc/s6-overlay/s6-rc.d" /package/admin/s6-overlay-@VERSION@/etc/s6-rc/sources
+s6-rc-compile -v"$cv" /run/s6/db "$etc/s6-overlay/s6-rc.d" /package/admin/s6-overlay-@VERSION@/etc/s6-rc/sources
 s6-rc-init -c /run/s6/db /run/service
 
 if timeout=`printcontenv S6_CMD_WAIT_FOR_SERVICES_MAXTIME` && test "$timeout" -ge 0 ; then : ; else
@@ -20,14 +42,14 @@ if timeout=`printcontenv S6_CMD_WAIT_FOR_SERVICES_MAXTIME` && test "$timeout" -g
 fi
 
 set +e
-s6-rc -v2 -u -t "$timeout" -- change "$top"
+s6-rc -v$v -u -t "$timeout" -- change "$top"
 r=$?
 set -e
 
 if test "$r" -ne 0 && b=0`printcontenv S6_BEHAVIOUR_IF_STAGE2_FAILS` && test "$b" -ne 0 ; then
-  echo '/run/s6/basedir/scripts/rc.init: warning: s6-rc failed to properly bring all the services up! Check your logs (in /run/uncaught-logs/current if you have in-container logging) for more information.' 1>&2
+  echo "$prog: warning: s6-rc failed to properly bring all the services up! Check your logs (in /run/uncaught-logs/current if you have in-container logging) for more information." 1>&2
   if test "$b" -ge 2 ; then
-    echo '/run/s6/basedir/scripts/rc.init: fatal: stopping the container.' 1>&2
+    echo "prog: fatal: stopping the container." 1>&2
     echo "$r" > /run/s6-linux-init-container-results/exitcode
     exec /run/s6/basedir/bin/halt
   fi

+ 6 - 2
layout/rootfs-overlay/package/admin/s6-overlay-@VERSION@/etc/s6-linux-init/skel/rc.shutdown

@@ -1,3 +1,7 @@
-#!@SHEBANGDIR@/execlineb -P
+#!/bin/sh
 
-s6-rc -v2 -bda change
+if v=`printcontenv S6_VERBOSITY` && s6-test "$v" =~ '^[[:digit:]]*$' ; then : ; else
+  v=2
+fi
+
+exec s6-rc -v$v -bda change

+ 0 - 0
layout/rootfs-overlay/package/admin/s6-overlay-@VERSION@/etc/s6-rc/sources/top/contents.d/user2