Skip to content
ComixHePublic

About

A tiny init for linux container.

Topics

Resources

Security policy

Stars

3 stars

Watchers

1 watching

Forks

Repository files navigation

zinit

A minimal, self-contained init for one Linux workload. It starts one workload, forwards signals to it or its process group, reaps orphans, rewrites signals and exit codes, handles the terminal and job control, and limits cleanup grace after the workload exits.

Static, no libc, and the supervision path uses no threads or dynamic allocation.

The message-only crash reporter also uses fixed storage, the full stack-trace reporter uses Zig's debug facilities and may allocate while symbolizing a crash.

Goal and scope

zinit covers the gap between a minimal PID 1 wrapper and a full service supervisor: policy-rich signal and lifecycle handling in one small, auditable binary. It supervises exactly one workload.

It is not a multi-service supervisor, does not restart workloads, and does not manage cgroups, namespaces, health checks or dependencies.

Use a service supervisor or the container runtime for those.

It is also not a replacement for a general-purpose OS init such as systemd or OpenRC.

Why zinit

  • Policy in one binary. Signal rewriting, exit-code mapping, a parent-death signal on the workload, process-group forwarding and bounded cleanup are available without a supervisor runtime or a shell wrapper.
  • Predictable footprint. No libc, no heap allocation on the supervision path, no supervisor threads, bounded event batches, a fixed descriptor set that does not grow with descendants.
  • Container and host/PTY use. The same binary can run as PID 1, as a subreaper below another init, or in an interactive shell with job control.
  • Modern kernel semantics. pidfd-backed process identity, preservation of queued realtime signal payloads on direct delivery, monotonic cleanup deadlines, and explicit capability fallbacks for older kernels.
  • Small, self-contained delivery. A static ELF with no runtime dependencies, shipped with checksums, an SPDX SBOM and cosign bundles.

Public contract

The public contract is the CLI, exit status, signal delivery, process scope, logging levels and limits documented in this file. Internal modules, syscall choices and fallback mechanisms are implementation details unless a documented behavior depends on them.

If a kernel feature is unavailable, zinit must either preserve the documented behavior or emit a warning/fail as described, it must not silently change the contract.

Behavioral changes require matching tests and release notes.

Requirements

Runtime

zinit is a static Linux binary with no libc or other runtime dependencies.

Architecture Minimum kernel target Release status
x86_64 2.6.27 ReleaseSmall / ReleaseSafe
aarch64 3.7 ReleaseSmall / ReleaseSafe
riscv64 4.15 Cross-build only, no native runner

These are build-target minimums, not runtime support claims. Current E2E runs use modern kernels, compiling for an older target does not replace running the corresponding kernel.

Feature Interface Minimum
-p parent-death signal PR_SET_PDEATHSIG 2.1.57
group signalling check waitid(P_PGID) 2.6.9
-t shutdown grace CLOCK_MONOTONIC 2.6.12
logging openat 2.6.16
-s orphan adoption PR_SET_CHILD_SUBREAPER 3.4
direct child signalling pidfd_send_signal 5.1
process handles clone(CLONE_PIDFD) 5.2
-g through a pidfd PIDFD_SIGNAL_PROCESS_GROUP 6.9

The table lists feature-specific minimums only, baseline process, signal and terminal interfaces are not repeated here. A missing optional interface follows the documented fallback or warning path.

Development

  • Linux host for native builds and tests
  • Zig, per minimum_zig_version in build.zig.zon
  • A modern kernel (5.10+) for the current E2E harness
  • Podman for zig build test-container

Cross-compilation is supported for Linux targets. It does not replace running the tests on the target kernel.

Install

zig build -Doptimize=ReleaseSmall
Prefer How
COPY --from in a Dockerfile ghcr.io/comixhe/zinit:<version>, the bare tag is size-optimized, -safe keeps Zig's runtime checks
A file release archives with SHA256SUMS, an SPDX SBOM and cosign bundles
Nix nix build github:ComixHe/zinit, #zinit-safe selects the checked build
Building the checkout, as above

Replace <version> with v followed by .version from build.zig.zon.

Usage

zinit [options] [--] <command> [args...]

-- is optional: the first non-option starts the command. Signals are numbers (15) or names (TERM, SIGTERM). -p and -r accept standard signals only.

Option Meaning
-h, --help Print usage and exit
-V, --version Print the version and exit
--log-level <level> error, warn, info or debug
-p, --signal <sig> Set the main workload's Linux parent-death signal
-s, --subreaper Adopt orphans, PID 1 adopts implicitly, but the flag is still requested and may fail if denied
-n, --new-session Put the workload in a new session, TSTP/TTIN/TTOU become STOP
-g, --forward-group Forward signals to the workload's initial process group
-t, --shutdown-timeout <secs> Descendant cleanup grace after exit, default 5
-r, --rewrite <OLD:NEW> Rewrite a forwarded signal, NEW=0 drops it, repeatable
-e, --expect-exit <code> Map a child exit code to 0, repeatable

Environment variables:

Variable Equivalent Value
ZINIT_LOG_LEVEL --log-level error, warn, info, debug
ZINIT_SUBREAPER -s presence
ZINIT_SHUTDOWN_TIMEOUT -t seconds
ZINIT_TRACING_CHILD -Dtracing-child ON / OFF

Exit status

Code Meaning
0 Success, help or version
1 Usage, startup or execution error
126 / 127 Workload found but not executable / not found
70 Internal panic or handled SEGV/BUS/ILL/FPE in message-only builds
otherwise The workload's code, or 128 + N for signal N, -e maps listed codes to 0

The message-only reporter makes one best-effort write through the prepared stderr sink. Full or broken pipes and sockets cannot delay its exit, the diagnostic may be lost. Regular-file writes retain the filesystem's I/O behavior.

If the cleanup clock fails after the main workload exits, zinit sends SIGKILL without waiting for the grace and preserves the workload's mapped exit status.

Process scope

Forwarding targets the main workload by default. -g targets the group created at startup, whose PGID is the main workload's initial PID. If group signalling fails, zinit logs the failure and does not fall back to signalling the main workload. Keep the main workload in that group for consistent forwarding across supported kernels and fallback paths.

-s reaps orphans that Linux reparents to zinit, including those that change group or session. When children remain after the main workload exits, cleanup attempts TERM, then KILL if needed at the -t grace deadline. Both sends target the initial group. Descendants that leave it may survive zinit when it is not PID 1. When namespace PID 1 exits, Linux separately kills the remaining namespace processes. Use the container runtime to enforce container-wide exit.

Delivery follows Linux permissions and security policy. A denied send is logged, supervision continues and retains the workload's eventual exit status. A group send may reach only the members zinit has permission to signal. -p applies to the main workload, Linux may clear it after credential changes or privileged exec.

Standard signals can coalesce. Queued data is preserved where supported, fallbacks may forward only the signal, with a warning. SIGCHLD drives reaping, KILL/STOP and zinit's own fault signals follow kernel/crash handling.

Logging

One line per event on stderr. Colour is used only on a terminal, there is no timestamp.

Level Events
error zinit cannot continue
warn A setup did not take effect, or a limit was reached, default
info The main workload's exit and problematic adopted descendants
debug Signal forwarding, rewrites, grace start and clean adopted exits

-Dlog-level sets the loudest level a build can print, -Ddefault-log-level sets the unasked level. A runtime request above the ceiling is an error, including ZINIT_LOG_LEVEL.

Common setups

No option is required when zinit is PID 1. The rest are independent:

zinit -s -- /usr/bin/my-daemon
zinit -g -- /bin/sh -c "my-server & wait"
zinit -n -- /usr/bin/my-app
zinit -e 143 -e 130 -- java -jar app.jar
zinit -r TERM:INT -- /usr/bin/my-app
zinit -r USR1:0 -- /usr/bin/my-app
zinit -p KILL -- /usr/bin/critical-service

Use -g when the workload is itself a shell that does not pass signals on. Use -s outside PID 1 when orphaned descendants must be reaped.

After starting the workload, zinit changes its own working directory to / to release its reference to the caller's directory. The workload keeps the original directory, including relative commands, PATH entries and file access. If this change fails, zinit warns and continues supervising. Other references can still prevent a mount from being unmounted.

Containers

Docker and Podman can use zinit through --init:

podman run --init --init-path ~/bin/zinit -it alpine sh

To make it the entrypoint of an image:

COPY --from=ghcr.io/comixhe/zinit:<version> /zinit /sbin/zinit
ENTRYPOINT ["/sbin/zinit", "--"]
CMD ["/bin/sh"]

Kubernetes has no --init-path, use zinit as command, or mount the image as an image volume. With shareProcessNamespace: true, add -s.

Compose's init: true uses the runtime's init. It uses zinit only when that runtime's default init path is zinit. Otherwise zinit runs below that init and needs -s.

-t bounds descendant cleanup after the main workload exits. It does not bound the main workload's response to a stop signal. Set the runtime's stop timeout longer than -t plus the workload's own stop time.

Sharing a uid normally avoids needing CAP_KILL. Different credentials may need that capability in the workload's user namespace, security policy still applies. Verify release signatures as described in SECURITY.md.

Build options

Option Meaning
-Doptimize=ReleaseSmall Smallest binary, ReleaseSafe keeps runtime checks
-Dlog-level=<level> Loudest level the build can print, default info
-Ddefault-log-level=<level> Unasked level, default warn, clamped to the ceiling
-Dpie=true Static PIE for ASLR, off by default
-Dstack-traces=<bool> Crash stack traces, on except for ReleaseSmall
-Dtracing-child=true Workload waits for SIGUSR1 before exec

For debugging the child with -Dtracing-child=true:

zig build -Dtracing-child=true -Doptimize=ReleaseSafe
ZINIT_TRACING_CHILD=ON strace -f -p "$(pgrep zinit)"
kill -USR1 <child-pid>

Crash reports

ReleaseSmall uses the message-only crash reporter to keep the binary small. A fatal signal prints one line and exits 70:

zinit: fatal signal 11 phase=supervise code=1 addr=0x0 at 0x10027a5

For a PIE build (-Dpie=true) the line also names pc, load_bias and elf_pc, use elf_pc for symbolization.

Build the matching symbols and resolve the address offline:

zig build -Doptimize=ReleaseSmall symbols
addr2line -e zig-out/dbg/zinit.dbg 0x10027a5

zig-out/dbg/zinit is the stripped binary, zinit.dbg is the symbol file. ReleaseSmall release archives include the matching <archive>-dbg.tar.gz, use the file from the same release.

To get Zig's full stack traces instead, build with -Dstack-traces=true, those binaries are larger.

Limits

  • A descendant that leaves the workload's process group, for example with setpgid or setsid, is outside zinit's reach.
  • -g addresses the group associated with the workload, a workload that moves to another group is not reached while its original group still has members.
  • Outside PID 1, zinit stops when the workload stops. Send SIGCONT to zinit to resume both, sending it only to the workload does not resume zinit. As PID 1, zinit cannot stop itself and keeps supervising.
  • The cleanup grace starts after the main workload exits. Escaped descendants and uninterruptible processes can outlive it, and the main workload's own shutdown time is not bounded by -t.
  • If zinit dies, cleanup depends on the environment: a PID namespace tears everything down, otherwise use -s or orphans are not reparented to zinit.
  • Realtime signal values are preserved when forwarded directly to the main workload. A process-group delivery may lose the value.
  • A stalled regular-file stderr sink can delay signal forwarding, reaping and shutdown. Full nonblocking sinks drop the current log event and may recover on a later event. A failed or partially written log line disables further logging for the rest of the run.

License

MIT. See LICENSE.

About

A tiny init for linux container.

Topics

Resources

Security policy

Stars

3 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages