diff options
Diffstat (limited to 'container')
| -rw-r--r-- | container/Containerfile | 9 | ||||
| -rwxr-xr-x | container/init | 22 | ||||
| -rwxr-xr-x | container/stop | 20 |
3 files changed, 37 insertions, 14 deletions
diff --git a/container/Containerfile b/container/Containerfile index f7fc00f..8aa03ec 100644 --- a/container/Containerfile +++ b/container/Containerfile @@ -1,8 +1,5 @@ FROM docker.io/library/debian:13 -# Flag that we are a devbox -RUN touch /run/.dbxenv - # Remove container-specific APT configurations, and install required packages RUN rm /etc/apt/apt.conf.d/docker-* && \ apt-get update && \ @@ -40,7 +37,7 @@ RUN echo "StreamLocalBindUnlink yes" >> /etc/ssh/sshd_config && \ echo "AuthorizedKeysFile /etc/ssh/authorized_keys" >> /etc/ssh/sshd_config && \ touch /etc/ssh/authorized_keys -# Set up the entrypoint -RUN mkdir -p /etc/dbx/rc.d -COPY init /sbin/init +# Set up the init and stop +RUN mkdir -p /etc/dbx +COPY init stop /sbin ENTRYPOINT ["/sbin/init"] diff --git a/container/init b/container/init index 49ee840..3f17b48 100755 --- a/container/init +++ b/container/init @@ -2,16 +2,22 @@ # SPDX-License-Identifier: GPL-3.0-only # SPDX-FileCopyrightText: 2026 Nicholas Rodrigues Lordello <[email protected]> -if [ ! -f /run/.dbxenv ]; then - echo "ERROR: not in a devbox" >&2 +if [ "$(id -u)" -ne 0 ]; then + printf '%s: operation not permitted\n' "$0" >&2 exit 1 fi -for rc in /etc/dbx/rc.d/*; do - if [ ! -f "$rc" ] || [ ! -x "$rc" ]; then - continue - fi - "$rc" || printf '%s: %s failed (%d)\n' "$0" "$rc" "$?" >&2 -done +touch /run/.dbxenv +printf "%d\n" "$$" >/run/dbx.pid + +if [ -f /etc/dbx/init.local ] && [ -x /etc/dbx/init.local ]; then + /etc/dbx/init.local || + printf '%s: init.local failed (%d)\n' "$0" "$?" >&2 +fi + +# The init process is not guaranteed to be on PID 1 for all runtimes (notably, +# `krun` will wrap the init process). Tell tini to act like an init process +# regardless of its PID. +export TINI_SUBREAPER=yes exec /usr/bin/tini /usr/sbin/sshd -- -D -e diff --git a/container/stop b/container/stop new file mode 100755 index 0000000..9affb9c --- /dev/null +++ b/container/stop @@ -0,0 +1,20 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-3.0-only +# SPDX-FileCopyrightText: 2026 Nicholas Rodrigues Lordello <[email protected]> + +if [ "$(id -u)" -ne 0 ]; then + printf '%s: operation not permitted\n' "$0" >&2 + exit 1 +fi + +if [ -x /etc/dbx/stop.local ]; then + /etc/dbx/stop.local || + printf '%s: stop.local failed (%d)\n' "$0" "$?" >&2 +fi + +if ! pid="$(cat /run/dbx.pid)"; then + printf '%s: could not read init PID file, assuming 1\n' "$0" >&2 + pid=1 +fi +kill -TERM "$pid" || + printf '%s: could not stop init[%s] (%d)\n' "$0" "$pid" "$?" >&2 |
