inithooks

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package inithooks provides support for running user-defined scripts on Gopherstack startup. Scripts are executed sequentially in the order they are listed, using the system shell. Any script that exits with a non-zero status is logged as an error but does not abort startup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLegacyReadyDirs

func DefaultLegacyReadyDirs() []string

DefaultLegacyReadyDirs are LocalStack's deprecated flat READY-stage script directories.

func DefaultRoots

func DefaultRoots() []string

DefaultRoots are the stage-directory roots scanned when present.

Types

type Manager

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

Manager discovers and runs <root>/<stage>.d scripts and tracks their status.

func NewManager

func NewManager(cfg ManagerConfig) *Manager

NewManager creates a Manager; a zero Timeout defaults to 30 s.

func (*Manager) Completed

func (m *Manager) Completed(stage Stage) bool

Completed reports whether the stage has finished running.

func (*Manager) Run

func (m *Manager) Run(ctx context.Context, stage Stage)

Run executes the stage's scripts sequentially, then marks the stage completed. Script failures are recorded and logged but never abort the stage.

func (*Manager) Status

func (m *Manager) Status() []ScriptStatus

Status returns every script seen so far, in stage then execution order.

type ManagerConfig

type ManagerConfig struct {
	Log *slog.Logger
	// Env is appended to the process environment for every script.
	Env   []string
	Roots []string
	// LegacyReadyDirs are flat script dirs run in READY after the ready.d scripts.
	LegacyReadyDirs []string
	Timeout         time.Duration
}

ManagerConfig configures a Manager.

type Result

type Result struct {
	Script string
	OK     bool
}

Result is the outcome of one init script.

type Runner

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

Runner executes a list of init scripts on startup.

func New

func New(scripts []string, timeout time.Duration, log *slog.Logger) *Runner

New creates a new Runner. scripts is the ordered list of shell script paths to execute. timeout is the per-script execution timeout (zero defaults to 30 s). log may be nil (in which case no logging is performed).

func (*Runner) Run

func (r *Runner) Run(ctx context.Context) []Result

Run executes each script sequentially and returns one Result per script. It blocks until all scripts have completed (or timed out). Errors from individual scripts are logged but do not stop subsequent scripts.

type ScriptStatus

type ScriptStatus struct {
	Stage Stage
	Name  string
	State State
	Error string
}

ScriptStatus is the status of one discovered script.

type Stage

type Stage string

Stage is an init lifecycle stage.

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

Lifecycle stages, matching LocalStack's init hook directories (<stage>.d).

func Stages

func Stages() []Stage

Stages lists every stage in lifecycle order.

type State

type State string

State is the per-script outcome reported at /_localstack/init.

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

Script states.

Jump to

Keyboard shortcuts

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