supervisor

package
v0.1.0-proto2d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2026 License: MPL-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunPhase0

func RunPhase0(ctx context.Context, d Phase0Deps) error

RunPhase0 executes the pre-userspace boot obligations in the order the kernel requires: the pidfd precondition first (nothing below is sound without it), subreaper next (a SIGCHLD needs a reaper), signal handlers after that (PID 1 has no implicit defaults), the reap loop started, then early mounts before any subsystem assumes them.

Every step that can fail fails closed - a broken /proc corrupts everything after it, and a kernel without pidfd makes signal delivery unsound for the whole process lifetime.

Types

type Phase0Deps

type Phase0Deps struct {
	// RequirePidfd asserts the kernel can pin a process with
	// pidfd_open. It runs before everything else because it is a
	// precondition rather than an obligation: without pidfd, os/exec
	// silently falls back to signalling by bare PID and every later
	// step is built on a guarantee that is not there (GAPI-DIV-016).
	RequirePidfd func() error
	// Subreaper marks this process as a child subreaper (prctl).
	Subreaper func() error
	// InstallSignal registers the explicit PID-1 signal handlers.
	InstallSignal func()
	// Mount runs the early filesystem mounts.
	Mount func([]mounts.MountSpec) error
	// StartReap launches the orphan reap loop for the process lifetime.
	StartReap func(context.Context)
	// SkipMounts honors --no-early-mounts (container environments).
	SkipMounts bool
}

Phase0Deps are the pre-userspace obligations, injected so the boot ordering is unit-testable without touching real syscalls; the wiring to the concrete kernel packages lives in the daemon entrypoint, and the real integration is proven by the PID-1 container e2e.

type Supervisor

type Supervisor struct {
	// contains filtered or unexported fields
}

Supervisor manages the GAPI runtime lifecycle.

func New

func New(cfg *config.Config) (*Supervisor, error)

New creates a new Supervisor instance.

func (*Supervisor) Bus

func (s *Supervisor) Bus() *eventbus.EventBus[*anypb.Any]

Bus returns the internal event bus.

func (*Supervisor) EnablePid1

func (s *Supervisor) EnablePid1(ctx context.Context) (func(action shutdown.Action), error)

EnablePid1 runs Phase 0 (pre-userspace) with the real kernel packages and installs the PID-1 signal semantics. Shutdown requests (signals here, the system.shutdown topic elsewhere) surface on ShutdownRequests(); the returned completion function runs after the runtime has stopped: sync, reverse umount, then reboot(2). Where reboot is not permitted (containers), the completion returns and the caller exits; for a container init, exiting IS poweroff.

func (*Supervisor) RequestShutdown

func (s *Supervisor) RequestShutdown(action shutdownpkg.Action)

RequestShutdown records a system shutdown request; the first request wins and repeats are absorbed (the machine only goes down once).

func (*Supervisor) Run

func (s *Supervisor) Run(ctx context.Context) error

Note: In a real library, Start might be non-blocking or accept a context. For now, we mirror the existing blocking behavior but allow external control via context cancellation if needed? The original used `runSupervisor()` which blocked on signal. We'll expose `Run()` which sets up handlers and blocks.

func (*Supervisor) ShutdownRequests

func (s *Supervisor) ShutdownRequests() <-chan shutdownpkg.Action

ShutdownRequests exposes the request channel; the daemon entrypoint selects on it to cancel the run context and complete the teardown.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL