launcher
launcher
¶
How the parent supervisor spawns one child process per service.
Each service runs as its own python -m terok_sandbox supervise-child
<service> <container_id> <sidecar_path> process on the parent's own
interpreter — -m resolves through terok_sandbox.__main__
whatever the install layout, so a child needs neither terok-sandbox
on $PATH nor a rendered wrapper.
Isolation is the child's own job: the instant it starts it hardens
itself (harden_self) and labels its own
sockets for SELinux, all before it opens the credential store. Nothing
about that depends on how the process was spawned, so the launch here is
a plain fork-exec. The optional Wayland wrapper enters its dedicated SELinux
domain before Python starts, so its later parent-death signals survive exec.
The parent's package search path survives wrapper-based
Python installations, but cwd imports remain excluded.
EXPECTED_PARENT_ENV = 'TEROK_SUPERVISOR_PARENT_PID'
module-attribute
¶
Internal startup guard against reparenting during the Wayland domain transition.
__all__ = ['ChildHandle', 'launch_child']
module-attribute
¶
ChildHandle(service, process, output=None)
dataclass
¶
launch_child(service, container_id, sidecar_path)
async
¶
Fork+exec python -m terok_sandbox supervise-child <service> ….
The parent's one spawn primitive. The child hardens itself and binds
its own socket. The environment preserves the parent's package paths; the
returned ChildHandle
is what the supervisor waits on and, at shutdown, signals.
Source code in src/terok_sandbox/supervisor/launcher.py
explained_preexec(step)
¶
Yield step as a preexec_fn whose failure reaches the parent with its reason.
CPython reports whatever a pre-exec step raises only as "Exception
occurred in preexec_fn.", so the reason the operator needs never leaves
the forked child. The yielded step writes that reason into a pipe
first; the spawn's generic error then leaves this block as a
RuntimeError carrying it.
Source code in src/terok_sandbox/supervisor/launcher.py
arm_parent_death_signal(sig)
¶
Ask the kernel to send sig to this process when its parent dies.
The one dead-man's switch behind every supervisor child: a parent killed
without teardown must not strand what it launched. False when the
kernel refused or this libc has no prctl; ctypes.get_errno()
then holds the reason. Whether that is fatal is the caller's call, and
so is checking that the parent it meant is the one still alive.
Source code in src/terok_sandbox/supervisor/launcher.py
relay_output(process, service)
async
¶
Forward bounded service output through the existing supervisor log.
Source code in src/terok_sandbox/supervisor/launcher.py
finish_output(output)
async
¶
Drain a stopped service without waiting forever on an inherited pipe.