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 ¶
const MaxCapturedOutput = 16 << 10
MaxCapturedOutput bounds the output retained per on-demand script run.
Variables ¶
var ( // ErrUnknownStage means the stage is not one of [Stages]. ErrUnknownStage = errors.New("unknown init stage") // ErrUnknownScript means no script of that name is registered in the stage. ErrUnknownScript = errors.New("init script not registered in stage") )
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) Run ¶
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) RunNamed ¶
RunNamed runs the discovered scripts of stage, or only the one whose file name equals name, and returns their exit status and bounded output. Only scripts found in the configured roots can run; name is matched against discovered base names, never used as a path.
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 Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner executes a list of init scripts on startup.
type ScriptRun ¶
type ScriptRun struct {
Stage Stage
Name string
Output string
Error string
ExitCode int
Truncated bool
}
ScriptRun is the outcome of one on-demand script execution.
type ScriptStatus ¶
ScriptStatus is the status of one discovered script.