inithooks

package
v0.0.1-alpha.21 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package inithooks discovers and executes user-provided shell scripts at well-known lifecycle stages, compatible with LocalStack's init hook system.

Scripts are placed in stage subdirectories (boot.d/, start.d/, ready.d/, shutdown.d/) under one or more base directories (e.g. /etc/localstack/init, /etc/overcast/init). They are executed in alphabetical order; subdirectories are traversed depth-first. A failing script does not block subsequent ones.

Index

Constants

This section is empty.

Variables

AllStages lists every stage in lifecycle order.

Functions

This section is empty.

Types

type InitStatus

type InitStatus struct {
	Completed map[Stage]bool `json:"completed"`
	Scripts   []ScriptResult `json:"scripts"`
}

InitStatus is the JSON response for GET /_overcast/init.

type Runner

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

Runner discovers and executes init hook scripts across configured directories.

func NewRunner

func NewRunner(dirs []string, env []string, timeout time.Duration, logger *zap.Logger) *Runner

NewRunner creates a Runner that will look for hook scripts in the given base directories. Each directory is expected to contain stage subdirectories (boot.d/, start.d/, ready.d/, shutdown.d/). The env slice is appended to the current process environment when executing scripts.

func (*Runner) Discover

func (r *Runner) Discover()

Discover scans all configured directories for hook scripts across all stages and populates the initial script list with UNKNOWN state. This should be called once after construction so the status endpoint can report discovered scripts before they run.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, stage Stage)

Run executes all hook scripts for the given stage synchronously. Scripts are run in alphabetical order with subdirectories traversed depth-first. If a script fails, the error is logged but execution continues with the next script.

func (*Runner) StageStatus

func (r *Runner) StageStatus(stage Stage) StageInfo

StageStatus returns the completion flag and scripts for a single stage. This is the payload for GET /_overcast/init/{stage}.

func (*Runner) Status

func (r *Runner) Status() InitStatus

Status returns the current state of all discovered scripts and stage completion flags. This is the payload for GET /_overcast/init.

type ScriptResult

type ScriptResult struct {
	Stage Stage       `json:"stage"`
	Name  string      `json:"name"`
	State ScriptState `json:"state"`
}

ScriptResult holds the state and metadata of a single init script.

type ScriptState

type ScriptState string

ScriptState tracks the execution state of a single init script.

const (
	StateUnknown    ScriptState = "UNKNOWN"
	StateRunning    ScriptState = "RUNNING"
	StateSuccessful ScriptState = "SUCCESSFUL"
	StateError      ScriptState = "ERROR"
)

type Stage

type Stage string

Stage is a lifecycle phase where init hooks can run.

const (
	StageBoot     Stage = "BOOT"
	StageStart    Stage = "START"
	StageReady    Stage = "READY"
	StageShutdown Stage = "SHUTDOWN"
)

func ParseStage

func ParseStage(s string) (Stage, bool)

ParseStage converts a string to a Stage, case-insensitively. Returns the stage and true if valid, or zero value and false if not.

type StageInfo

type StageInfo struct {
	Completed bool           `json:"completed"`
	Scripts   []ScriptResult `json:"scripts"`
}

StageInfo is the JSON response for GET /_overcast/init/{stage}.

Jump to

Keyboard shortcuts

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