safemode

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package safemode counts funcd's unclean starts in <storage.dataDir>/safemode.json and turns a crash loop into a held start, then a stop that names the operator's restore (ADR-0207 Decisions 3 to 5). It records the last funcd upgrade, whose pre-upgrade generation is the way back.

Index

Constants

View Source
const ExitStopped = 70

ExitStopped is the exit status of a stopped start; both units carry RestartPreventExitStatus=70.

View Source
const MarkerReason = "safe-mode"

MarkerReason is the hold marker's reason when safe mode holds the platform.

View Source
const StateFile = "safemode.json"

StateFile is the start counter in the data directory.

Variables

This section is empty.

Functions

func Begin

func Begin(dataDir, version string, cfg Config) (*Start, State, Mode, error)

Begin reads StateFile and returns the state before this start and the mode: unclean below AfterCrashes is Normal, below twice it Held, else Stopped with a nil *Start and a *StoppedError, nothing written. Otherwise the start is recorded unclean under version. An absent file is the zero state; one that does not read or decode is fault.Internal, and no start is recorded.

func RecordUpgrade

func RecordUpgrade(dataDir string, u Upgrade) error

RecordUpgrade records u as the last upgrade and the count as clean (Decision 1 step 6).

func Reset

func Reset(dataDir string) error

Reset sets unclean and lastError to zero and keeps the upgrade: `funcd safe-mode reset` (Decision 5). The hold marker stays, so the next start is held.

Types

type Config

type Config struct {
	AfterCrashes int
	StableAfter  time.Duration
}

Config is recovery.safeMode, parsed: AfterCrashes at least 1.

type Mode

type Mode int

Mode is how a start goes on (Decision 4).

const (
	Normal Mode = iota
	Held
	Stopped
)

type Start

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

Start is one counted start: Clean and Failed record how it ended.

func (*Start) Clean

func (s *Start) Clean() error

Clean records the start clean: unclean = 0. A nil Start records nothing.

func (*Start) Failed

func (s *Start) Failed(err error) error

Failed keeps err as lastError; the start stays as Begin or Clean left it. A nil Start records nothing.

type State

type State struct {
	Unclean   int      `json:"unclean"`
	Version   string   `json:"version,omitempty"`
	LastError string   `json:"lastError,omitempty"`
	Upgrade   *Upgrade `json:"upgrade,omitempty"`
}

State is StateFile: the unclean starts in a row, the version of the last start, the error the last failed start returned, and the last upgrade.

type StoppedError

type StoppedError struct{ State State }

StoppedError is a stopped start: it names the count, the last error and the next command.

func (*StoppedError) Error

func (e *StoppedError) Error() string

type Upgrade

type Upgrade struct {
	From       string         `json:"from"`
	To         string         `json:"to"`
	Generation *backup.GenRef `json:"generation,omitempty"`
	At         v1.Timestamp   `json:"at"`
}

Upgrade is the last funcd upgrade: the versions and the pre-upgrade generation, nil after --no-snapshot.

Jump to

Keyboard shortcuts

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