diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5994828 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +dist/ +.DS_Store diff --git a/builder/build-latest b/builder/build-latest index 1379923..ff17e18 100755 --- a/builder/build-latest +++ b/builder/build-latest @@ -95,15 +95,22 @@ for output in "${outputs[@]}"; do mkdir -p $overlaydstpath/etc/{cont-init.d,fix-attrs.d,services.d} mkdir -p $overlaydstpath/var/log/s6-uncaught-logs + # create event directory in fdholder, its needed for no-catchall + # stage2 wake up + mkdir -p $overlaydstpath/etc/s6/services/s6-fdholderd/event + chmod 3730 $overlaydstpath/etc/s6/services/s6-fdholderd/event + # fix fix-attrs perms chmod 0755 $overlaydstpath/usr/bin/fix-attrs # fix init perms chmod 0755 $overlaydstpath/init - chmod 0755 $overlaydstpath/etc/s6/init/init-stage* - chmod 0755 $overlaydstpath/etc/s6/service/.s6-svscan/{crash,finish} - chmod 0755 $overlaydstpath/etc/s6/service/s6-fdholderd/run - chmod 0755 $overlaydstpath/etc/s6/service/s6-svscan-log/run + chmod 0755 $overlaydstpath/etc/s6/init/init-* + chmod 0755 $overlaydstpath/etc/s6/init-catchall/init-* + chmod 0755 $overlaydstpath/etc/s6/init-no-catchall/init-* + chmod 0755 $overlaydstpath/etc/s6/services/.s6-svscan/{crash,finish} + chmod 0755 $overlaydstpath/etc/s6/services/s6-fdholderd/run + chmod 0755 $overlaydstpath/etc/s6/services/s6-svscan-log/run # copy debugging tools & fix perms if [ "${edition}" == "debug" ]; then @@ -112,7 +119,11 @@ for output in "${outputs[@]}"; do fi # dist! - tar -zcvf $overlaytarpath -C $overlaydstpath ./ + tar --owner=root --group=root \ + -zcvf \ + $overlaytarpath \ + -C $overlaydstpath \ + ./ done done diff --git a/builder/overlay-rootfs/etc/s6/init-catchall/init-stage1 b/builder/overlay-rootfs/etc/s6/init-catchall/init-stage1 new file mode 100755 index 0000000..ccb7f02 --- /dev/null +++ b/builder/overlay-rootfs/etc/s6/init-catchall/init-stage1 @@ -0,0 +1,59 @@ +#!/usr/bin/execlineb -S0 + +## +## ensure our vital fifo exists +## + +if { s6-mkfifo -m 0600 -- /var/run/s6/uncaught-logs-fifo } + +## +## ensure ownership & permissions for our vital files +## + +if { s6-rmrf /var/log/s6-uncaught-logs } +if { s6-mkdir -p /var/log/s6-uncaught-logs } +if { s6-envuidgid -D 32768:32768 nobody s6-chown -U /var/log/s6-uncaught-logs } +if { s6-chmod 2700 /var/log/s6-uncaught-logs } + + +## +## init the scandir with our base services +## + +if { s6-rmrf /var/run/s6/services } +if { s6-hiercopy /etc/s6/services /var/run/s6/services } + + +## +## fork the "init-stage2" script +## + +background +{ + # block until the supervision tree is running + redirfd -w 3 /var/run/s6/uncaught-logs-fifo + fdclose 3 + + # add some environment + s6-envdir -- /etc/s6/init/env-stage2 + + # run the script + /etc/s6/init-catchall/init-stage2 $@ +} +unexport ! + + +## +## run the rest of stage 1 with sanitized descriptors +## + +redirfd -r 0 /dev/null +redirfd -wnb 1 /var/run/s6/uncaught-logs-fifo +fdmove -c 2 1 + + +## +## start the supervision tree +## + +s6-svscan -t0 /var/run/s6/services diff --git a/builder/overlay-rootfs/etc/s6/init-catchall/init-stage2 b/builder/overlay-rootfs/etc/s6/init-catchall/init-stage2 new file mode 100755 index 0000000..f351cec --- /dev/null +++ b/builder/overlay-rootfs/etc/s6/init-catchall/init-stage2 @@ -0,0 +1,24 @@ +#!/usr/bin/execlineb -S0 + +# This file is executed (not as process 1!) as soon as s6-svscan +# starts, with the original stdin/out/err, but NOT the original +# environment. +# Purpose of this file: to perform all the one-time initialization tasks. + +if -nt +{ + if + { + redirfd -w 1 /var/run/s6/uncaught-logs-fifo + fdmove -c 2 1 + + /etc/s6/init/init-stage2-fix-attrs + /etc/s6/init/init-stage2-cont-inits + /etc/s6/init/init-stage2-services + } + + /etc/s6/init/init-stage2-cmd $@ +} + +# if anything in the if -nt { } block fails, control jumps here. +s6-echo -- "\n!!!!!\n init-stage2 failed.\n Logs are in /var/log/s6-uncaught-logs\n!!!!!" diff --git a/builder/overlay-rootfs/etc/s6/init-no-catchall/init-stage1 b/builder/overlay-rootfs/etc/s6/init-no-catchall/init-stage1 new file mode 100644 index 0000000..c3fd626 --- /dev/null +++ b/builder/overlay-rootfs/etc/s6/init-no-catchall/init-stage1 @@ -0,0 +1,48 @@ +#!/usr/bin/execlineb -S0 + +## +## init the scandir with our base services +## + +if { s6-rmrf /var/run/s6/services } +if { s6-hiercopy /etc/s6/services /var/run/s6/services } +if { s6-rmrf /var/run/s6/services/s6-svscan-log } + + +## +## fork the "init-stage2" script +## + +background +{ + # block until the supervision tree is running + # NOTE: start waiting as soon as possible because we can get + # into a race condition if "s" was already sent before we + # started listening to the fifodir. + if + { + # keep stderr open, but avoid "s" printing to the outside + redirfd -w 1 /dev/null + s6-ftrig-wait /var/run/s6/services/s6-fdholderd/event "s" + } + + # add some environment + s6-envdir -- /etc/s6/init/env-stage2 + + # run the script + /etc/s6/init-no-catchall/init-stage2 $@ +} +unexport ! + +## +## run the rest of stage 1 with sanitized descriptors +## + +redirfd -r 0 /dev/null + + +## +## start the supervision tree +## + +s6-svscan -t0 /var/run/s6/services diff --git a/builder/overlay-rootfs/etc/s6/init-no-catchall/init-stage2 b/builder/overlay-rootfs/etc/s6/init-no-catchall/init-stage2 new file mode 100644 index 0000000..c4b67d3 --- /dev/null +++ b/builder/overlay-rootfs/etc/s6/init-no-catchall/init-stage2 @@ -0,0 +1,21 @@ +#!/usr/bin/execlineb -S0 + +# This file is executed (not as process 1!) as soon as s6-svscan +# starts, with the original stdin/out/err, but NOT the original +# environment. +# Purpose of this file: to perform all the one-time initialization tasks. + +if -nt +{ + if + { + /etc/s6/init/init-stage2-fix-attrs + /etc/s6/init/init-stage2-cont-inits + /etc/s6/init/init-stage2-services + } + + /etc/s6/init/init-stage2-cmd $@ +} + +# if anything in the if -nt { } block fails, control jumps here. +s6-echo -- "\n!!!!!\n init-stage2 failed.\n!!!!!" diff --git a/builder/overlay-rootfs/etc/s6/init/init-stage1 b/builder/overlay-rootfs/etc/s6/init/init-stage1 old mode 100755 new mode 100644 index 69c9407..9ddfd11 --- a/builder/overlay-rootfs/etc/s6/init/init-stage1 +++ b/builder/overlay-rootfs/etc/s6/init/init-stage1 @@ -18,61 +18,19 @@ /usr/bin/s6-envdir /etc/s6/init/env /usr/bin/exec -- - ## -## ensure our vital fifo exists +## route based on what was provided in S6_USE_CATCHALL_LOGGER ## -if { s6-mkfifo -m 0600 -- /var/run/s6/uncaught-logs-fifo } - -## -## ensure ownership & permissions for our vital files -## - -if { s6-rmrf /var/log/s6-uncaught-logs } -if { s6-mkdir -p /var/log/s6-uncaught-logs } -if { s6-envuidgid -D 32768:32768 nobody s6-chown -U /var/log/s6-uncaught-logs } -if { s6-chmod 2700 /var/log/s6-uncaught-logs } - - -## -## init the scandir with our base services -## - -if { s6-rmrf /var/run/s6/service } -if { s6-hiercopy /etc/s6/service /var/run/s6/service } - - -## -## fork the "init-stage2" script -## - -background +backtick -n -D 0 S6_USE_CATCHALL_LOGGER { - # add some environment - s6-envdir -- /etc/s6/init/env-stage2 - - # block until the supervision tree is running - redirfd -w 3 /var/run/s6/uncaught-logs-fifo - fdclose 3 - - # run the script - /etc/s6/init/init-stage2 $@ + if { s6-test -f /var/run/s6/container_environment/S6_USE_CATCHALL_LOGGER } + redirfd -r 0 /var/run/s6/container_environment/S6_USE_CATCHALL_LOGGER + s6-cat } -unexport ! - - -## -## run the rest of stage 1 with sanitized descriptors -## - -redirfd -r 0 /dev/null -redirfd -wnb 1 /var/run/s6/uncaught-logs-fifo -fdmove -c 2 1 - - -## -## start the supervision tree -## - -s6-svscan -t0 /var/run/s6/service +import -u S6_USE_CATCHALL_LOGGER +ifelse { s6-test ${S6_USE_CATCHALL_LOGGER} -eq 1 } +{ + /etc/s6/init-catchall/init-stage1 $@ +} +/etc/s6/init-no-catchall/init-stage1 $@ diff --git a/builder/overlay-rootfs/etc/s6/init/init-stage2 b/builder/overlay-rootfs/etc/s6/init/init-stage2 deleted file mode 100755 index cd678ec..0000000 --- a/builder/overlay-rootfs/etc/s6/init/init-stage2 +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/execlineb -S0 - -# This file is executed (not as process 1!) as soon as s6-svscan -# starts, with the original stdin/out/err, but NOT the original -# environment. -# Purpose of this file: to perform all the one-time initialization tasks. - -if -nt -{ - if - { - redirfd -w 1 /var/run/s6/uncaught-logs-fifo - fdmove -c 2 1 - - - ## - ## fix-attrs.d: ensure owners and permissions are correct - ## - - if { s6-echo "[fix-attrs.d] applying owners & permissions fixes..." } - if - { - pipeline { s6-ls -0 -- /etc/fix-attrs.d } - pipeline { s6-sort -0 -- } - forstdin -0 -- i - import -u i - if { s6-echo -n -- "[fix-attrs.d] applying ${i}... " } - foreground { redirfd -r 0 /etc/fix-attrs.d/${i} fix-attrs } - import -u ? s6-echo -- " exited ${?}" - } - if { s6-echo -- "[fix-attrs.d] done." } - - - ## - ## cont-init.d: one-time init scripts - ## - - if { s6-echo "[cont-init.d] executing container initialization scripts..." } - if - { - pipeline { s6-ls -0 -- /etc/cont-init.d } - pipeline { s6-sort -0 -- } - forstdin -0 -- i - import -u i - if { s6-echo -n -- "[cont-init.d] executing ${i}... " } - foreground { with-contenv /etc/cont-init.d/${i} } - import -u ? s6-echo -- " ... exited ${?}" - } - if { s6-echo -- "[cont-init.d] done." } - - - ## - ## services.d: long-lived processes to be supervised - ## - - if { s6-echo "[services.d] starting services" } - if - { - pipeline { s6-ls -0 -- /etc/services.d } - forstdin -0 -p -- i - import -u i - if { s6-test -d /etc/services.d/${i} } - s6-hiercopy /etc/services.d/${i} /var/run/s6/service/${i} - } - if { s6-svscanctl -a /var/run/s6/service } - if { s6-echo -- "[services.d] done." } - - } - - - ## - ## The init is complete. If the user has given a CMD, run it now, then - ## kill everything when it exits. - ## - - if -t { s6-test $# -ne 0 } - foreground { s6-setsid -gq -- with-contenv $@ } - foreground { import -u ? s6-echo "${1} exited ${?}. Stopping the supervision tree." } - foreground { s6-svscanctl -t /var/run/s6/service } - - # Race condition here, but it's ok: the sync in stage 3 takes ages, - # and if we get killed by the SIGTERM instead of the SIGKILL, meh, who cares. - - # Wait to be nuked - s6-pause -th -} - -# if anything in the if -nt { } block fails, control jumps here. -s6-echo -- "\n!!!!!\n init-stage2 failed.\n Logs are in /var/log/s6-uncaught-logs\n!!!!!" diff --git a/builder/overlay-rootfs/etc/s6/init/init-stage2-cmd b/builder/overlay-rootfs/etc/s6/init/init-stage2-cmd new file mode 100644 index 0000000..6d17d76 --- /dev/null +++ b/builder/overlay-rootfs/etc/s6/init/init-stage2-cmd @@ -0,0 +1,17 @@ +#!/usr/bin/execlineb -S0 + +## +## The init is complete. If the user has given a CMD, run it now, then +## kill everything when it exits. +## + +if -t { s6-test $# -ne 0 } +foreground { s6-setsid -gq -- with-contenv $@ } +foreground { import -u ? s6-echo "${1} exited ${?}. Stopping the supervision tree." } +foreground { s6-svscanctl -t /var/run/s6/services } + +# Race condition here, but it's ok: the sync in stage 3 takes ages, +# and if we get killed by the SIGTERM instead of the SIGKILL, meh, who cares. + +# Wait to be nuked +s6-pause -th diff --git a/builder/overlay-rootfs/etc/s6/init/init-stage2-cont-inits b/builder/overlay-rootfs/etc/s6/init/init-stage2-cont-inits new file mode 100644 index 0000000..fb15053 --- /dev/null +++ b/builder/overlay-rootfs/etc/s6/init/init-stage2-cont-inits @@ -0,0 +1,19 @@ +#!/usr/bin/execlineb -S0 + +## +## cont-init.d: one-time init scripts +## + +if { s6-echo "[cont-init.d] executing container initialization scripts..." } +if +{ + pipeline { s6-ls -0 -- /etc/cont-init.d } + pipeline { s6-sort -0 -- } + forstdin -0 -- i + import -u i + if { s6-echo -n -- "[cont-init.d] executing ${i}... " } + foreground { with-contenv /etc/cont-init.d/${i} } + import -u ? s6-echo -- " ... exited ${?}" +} +if { s6-echo -- "[cont-init.d] done." } +$@ diff --git a/builder/overlay-rootfs/etc/s6/init/init-stage2-fix-attrs b/builder/overlay-rootfs/etc/s6/init/init-stage2-fix-attrs new file mode 100644 index 0000000..2e3afc0 --- /dev/null +++ b/builder/overlay-rootfs/etc/s6/init/init-stage2-fix-attrs @@ -0,0 +1,19 @@ +#!/usr/bin/execlineb -S0 + +## +## fix-attrs.d: ensure owners and permissions are correct +## + +if { s6-echo "[fix-attrs.d] applying owners & permissions fixes..." } +if +{ + pipeline { s6-ls -0 -- /etc/fix-attrs.d } + pipeline { s6-sort -0 -- } + forstdin -0 -- i + import -u i + if { s6-echo -n -- "[fix-attrs.d] applying ${i}... " } + foreground { redirfd -r 0 /etc/fix-attrs.d/${i} fix-attrs } + import -u ? s6-echo -- " exited ${?}" +} +if { s6-echo -- "[fix-attrs.d] done." } +$@ diff --git a/builder/overlay-rootfs/etc/s6/init/init-stage2-services b/builder/overlay-rootfs/etc/s6/init/init-stage2-services new file mode 100644 index 0000000..5fcaa32 --- /dev/null +++ b/builder/overlay-rootfs/etc/s6/init/init-stage2-services @@ -0,0 +1,18 @@ +#!/usr/bin/execlineb -S0 + +## +## services.d: long-lived processes to be supervised +## + +if { s6-echo "[services.d] starting services" } +if +{ + pipeline { s6-ls -0 -- /etc/services.d } + forstdin -0 -p -- i + import -u i + if { s6-test -d /etc/services.d/${i} } + s6-hiercopy /etc/services.d/${i} /var/run/s6/services/${i} +} +if { s6-svscanctl -a /var/run/s6/services } +if { s6-echo -- "[services.d] done." } +$@ diff --git a/builder/overlay-rootfs/etc/s6/init/init-stage3 b/builder/overlay-rootfs/etc/s6/init/init-stage3 old mode 100755 new mode 100644 diff --git a/builder/overlay-rootfs/etc/s6/service/.s6-svscan/crash b/builder/overlay-rootfs/etc/s6/services/.s6-svscan/crash similarity index 100% rename from builder/overlay-rootfs/etc/s6/service/.s6-svscan/crash rename to builder/overlay-rootfs/etc/s6/services/.s6-svscan/crash diff --git a/builder/overlay-rootfs/etc/s6/service/.s6-svscan/finish b/builder/overlay-rootfs/etc/s6/services/.s6-svscan/finish similarity index 100% rename from builder/overlay-rootfs/etc/s6/service/.s6-svscan/finish rename to builder/overlay-rootfs/etc/s6/services/.s6-svscan/finish diff --git a/builder/overlay-rootfs/etc/s6/service/s6-fdholderd/down b/builder/overlay-rootfs/etc/s6/services/s6-fdholderd/down similarity index 100% rename from builder/overlay-rootfs/etc/s6/service/s6-fdholderd/down rename to builder/overlay-rootfs/etc/s6/services/s6-fdholderd/down diff --git a/builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/0/allow b/builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/0/allow similarity index 100% rename from builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/0/allow rename to builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/0/allow diff --git a/builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_GETDUMP b/builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_GETDUMP similarity index 100% rename from builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_GETDUMP rename to builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_GETDUMP diff --git a/builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_LIST b/builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_LIST similarity index 100% rename from builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_LIST rename to builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_LIST diff --git a/builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_RETRIEVE_REGEX b/builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_RETRIEVE_REGEX similarity index 100% rename from builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_RETRIEVE_REGEX rename to builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_RETRIEVE_REGEX diff --git a/builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_SETDUMP b/builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_SETDUMP similarity index 100% rename from builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_SETDUMP rename to builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_SETDUMP diff --git a/builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_STORE_REGEX b/builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_STORE_REGEX similarity index 100% rename from builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_STORE_REGEX rename to builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/0/env/S6_FDHOLDER_STORE_REGEX diff --git a/builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/default/allow b/builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/default/allow similarity index 100% rename from builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/default/allow rename to builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/default/allow diff --git a/builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/default/env/S6_FDHOLDER_LIST b/builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/default/env/S6_FDHOLDER_LIST similarity index 100% rename from builder/overlay-rootfs/etc/s6/service/s6-fdholderd/rules/uid/default/env/S6_FDHOLDER_LIST rename to builder/overlay-rootfs/etc/s6/services/s6-fdholderd/rules/uid/default/env/S6_FDHOLDER_LIST diff --git a/builder/overlay-rootfs/etc/s6/service/s6-fdholderd/run b/builder/overlay-rootfs/etc/s6/services/s6-fdholderd/run similarity index 100% rename from builder/overlay-rootfs/etc/s6/service/s6-fdholderd/run rename to builder/overlay-rootfs/etc/s6/services/s6-fdholderd/run diff --git a/builder/overlay-rootfs/etc/s6/service/s6-svscan-log/run b/builder/overlay-rootfs/etc/s6/services/s6-svscan-log/run similarity index 100% rename from builder/overlay-rootfs/etc/s6/service/s6-svscan-log/run rename to builder/overlay-rootfs/etc/s6/services/s6-svscan-log/run