From 7f8a16da8a83f447446d9855f15f53dc6edff42f Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 20 Dec 2023 14:24:48 -0700 Subject: [PATCH] Switch to non-PID1 init --- Containerfile | 6 +++--- README.md | 10 ++++++++++ etc/apk/protected_paths.d/toolbox.list | 3 +++ etc/runit/2 | 3 --- etc/runit/3 | 3 --- etc/runit/1 => sbin/toolbox-init | 8 +++++++- 6 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 etc/apk/protected_paths.d/toolbox.list delete mode 100755 etc/runit/2 delete mode 100755 etc/runit/3 rename etc/runit/1 => sbin/toolbox-init (75%) diff --git a/Containerfile b/Containerfile index 6673bba..0a08e1e 100644 --- a/Containerfile +++ b/Containerfile @@ -1,5 +1,5 @@ FROM alpine -RUN apk update -RUN apk add alpine-conf doas runit openssh-server +RUN apk add --no-cache alpine-conf doas runit openssh-server COPY etc/ /etc/ -CMD [ "/sbin/runit" ] +COPY /sbin /sbin/ +CMD [ "/sbin/toolbox-init" ] diff --git a/README.md b/README.md index 847a1ec..b9e1cd0 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,16 @@ Once set up, you should be able to ssh in for most of your needs. +Startup scripts +--------------- + +The system uses [runit](http://smarden.org/runit/). +If you drop an executable in `/etc/service/*/run`, +runit will run it. + +Be sure to `lbu commit` if you're making startup scripts. + + Podman vs Docker ---------------- diff --git a/etc/apk/protected_paths.d/toolbox.list b/etc/apk/protected_paths.d/toolbox.list new file mode 100644 index 0000000..526d0b2 --- /dev/null +++ b/etc/apk/protected_paths.d/toolbox.list @@ -0,0 +1,3 @@ +-/etc/apk/protected_paths.d/toolbox.list +-/etc/service/*/supervise +-/etc/service/*/log/supervise diff --git a/etc/runit/2 b/etc/runit/2 deleted file mode 100755 index 7332592..0000000 --- a/etc/runit/2 +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/sh - -exec /sbin/runsvdir /etc/service diff --git a/etc/runit/3 b/etc/runit/3 deleted file mode 100755 index 3f70c8d..0000000 --- a/etc/runit/3 +++ /dev/null @@ -1,3 +0,0 @@ -#! /bin/sh - -echo "*** Goodbye." diff --git a/etc/runit/1 b/sbin/toolbox-init similarity index 75% rename from etc/runit/1 rename to sbin/toolbox-init index cae6183..6cf670e 100755 --- a/etc/runit/1 +++ b/sbin/toolbox-init @@ -1,5 +1,8 @@ #! /bin/sh +exec > /var/log/boot.log +exec 2>&1 + error () { printf '\033[31mFLAGRANT SYSTEM ERROR\033[0m - %s' "$*" >> /etc/motd } @@ -13,8 +16,11 @@ apkovl=/mnt/toolbox/lbu/$(hostname).apkovl.tar.gz if [ -f $apkovl ]; then tar xf $apkovl || error "restoring system: untar $apkovl failed" else - echo "$apkovl missing, skipping restore" + echo "$apkovl missing; run 'lbu commit' to create it" fi echo "*** Updating packages" apk fix + +echo "*** Handing off to runsvdir" +exec /sbin/runsvdir /etc/service