lifecycle

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package lifecycle detects the discrete host lifecycle events the agent emits as the strong-delivery signal class: boot, unexpected_reboot, clean_shutdown, oom_kill and fs_readonly. It reads only unprivileged /proc files and persists two small 0600 files in the state directory: a state file (the last-seen boot_id and a periodically refreshed liveness timestamp) and a clean_shutdown marker written on SIGTERM. The marker is what makes the next boot a clean boot rather than an unexpected reboot.

Events are emitted into the shared event queue. On a crash there is no live send; the safety net is the exit spool plus the boot backfill: events queued here are spooled on exit and delivered after the next start.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Detector

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

Detector holds the lifecycle detection state and the persistence paths.

func New

func New(fs platform.FS, clock platform.Clock, emitter Emitter, stateDir string) *Detector

New builds a Detector rooted at stateDir.

func (*Detector) Shutdown

func (d *Detector) Shutdown(context.Context)

Shutdown runs on SIGTERM: it emits clean_shutdown and persists the marker so the next boot is recognised as clean. It is best-effort and must not block.

func (*Detector) Startup

func (d *Detector) Startup(context.Context)

Startup runs once before the first report: it compares the current boot_id to the persisted one and emits boot or unexpected_reboot on a change, consumes the clean_shutdown marker, refreshes the persisted state, and seeds the oom and read-only-mount baselines so Tick reports only transitions.

func (*Detector) Tick

func (d *Detector) Tick(context.Context)

Tick runs each collect interval: it emits oom_kill on a positive vmstat delta and fs_readonly when a previously writable mount has flipped read-only, and refreshes the liveness timestamp at most once per flushEvery.

type Emitter

type Emitter interface {
	Emit(t wire.EventType, meta map[string]string)
}

Emitter raises a lifecycle event. It matches internal/event.Emitter without importing it, mirroring the buffer package.

Jump to

Keyboard shortcuts

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