Expand description
Daemonization for waratah start (spawn-self detached).
Default waratah start re-executes this same binary as a detached child
carrying the original arguments plus the hidden --daemon-ready <path>
marker, so the parent can return to the shell immediately and the cluster
keeps running under waratah stop. --foreground (or --query /
--no-http, which imply it) skips this module entirely.
§Parent side (run_detached)
- Resolve the run layout (log dir) and mint a per-attempt status file
name —
start-status-{pid}-{millis}.txt— so two concurrentwaratah startattempts never share a handshake file: a “still starting” attempt’s latereadycan never be attributed to another attempt, and no stale verdict can survive into a new attempt. The spawner removes the file on every exit. - Spawn
current_exe()with the parent’s own arguments plus--daemon-ready, fully detached: new process group (Unix) orDETACHED_PROCESS | CREATE_NEW_PROCESS_GROUP(Windows), stdin null, stdout →output.txt, stderr →error.txt(append). Storage children spawned later by the daemon inherit those fds, so their output lands in the same files with no per-child plumbing. - Poll the status file for one line —
readyorerror: <message>— up toREADY_TIMEOUT. The child writesreadyonly once startup is complete and the HTTP socket is bound; a first boot with geo/temporal auto-rebuilds can sit in between for far longer than the timeout, so a timeout with a live child is reported as “still starting” (exit 0), not as a failure. - Ctrl+C / SIGTERM during the wait reaches only the foreground spawner (the daemon is in its own process group), so the spawner answers for the cluster: kill the starting group — SIGTERM, short grace, SIGKILL — clear the status file and the daemon’s pidfile, and fail the invocation.
§Child side (run_child)
Runs the normal dev::start path with three additions: the readiness
status write (via DevOptions::ready_file, reported by run_session
right before the serve loop), the file-backed debug sink
(DevOptions::debug_file → debug.txt, truncated each start), and a
pidfile even for the memory backend (the working directory) so
waratah stop without --data-dir can find the daemon.
The daemon never changes its working directory: relative --data-dir
paths and the memory backend’s cwd pidfile/logs depend on it.
Structs§
- Detach
Plan - What the spawner needs to detach a cluster and report the result.
Constants§
- DEBUG_
FILE - ERROR_
FILE - KILL_
GRACE 🔒 - How long a cancelled start’s SIGTERM gets before the whole process group is SIGKILLed. Deliberately shorter than the daemon’s own 5s HTTP drain: a cancelled start prefers returning the prompt over a fully drained teardown.
- OUTPUT_
FILE - Log file names inside the log dir.
- READY_
TIMEOUT 🔒 - How long the spawner waits for the daemon child’s
readyline. Startup that outlives this (index auto-rebuilds on a first boot) is reported as “still starting” — the child keeps booting in the background. - STATUS_
PREFIX 🔒 - Per-attempt status file prefix in the log dir. The full name is
start-status-{spawner pid}-{unix millis}.txt: two concurrentwaratah startattempts always differ in pid, so they never share a handshake file.
Functions§
- detach 🔒
- Make
commandsurvive the parent and the terminal. - kill_
starting_ 🔒cluster - Kill a cluster cancelled mid-startup. The signal reached only the
foreground spawner: the daemon sits in its own process group (see
detach), together with the storage children it already spawned, so the whole group must be killed from here — SIGTERM first (the daemon’s own handler tears the children down and removes its pidfile), SIGKILL to the group pastKILL_GRACE. - log_dir
- Where the daemon writes its log files:
{data_dir}/logswhen a data dir is set, otherwise the working directory (memory backend). - print_
daemonized 🔒 - The parent’s success report: pid, URLs, log paths, stop hint.
- read_
status 🔒 - First line of the status file, if it exists and is non-empty.
- report_
ready - Write the readiness line (called by
run_sessiononce startup is complete and the serve loop is about to begin). - run_
child - The daemon-child half: run the normal start path and funnel the outcome into the status file the spawner is polling.
- run_
detached - Spawn this binary as a detached daemon and report the outcome.
- status_
file 🔒 - Mint this attempt’s status path (see
STATUS_PREFIX). No I/O. - wait_
for_ 🔒interrupt - Resolve when the operator interrupts the start wait: SIGINT or SIGTERM on Unix, Ctrl+C on Windows.
- write_
status 🔒 - One-line status write. Newlines are flattened so the file always holds exactly one parseable line.