state

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package state is Outpost's local record of observed reality: what is running, what state it is in, and what has happened recently.

The manifest, not this store, is the source of truth for which services exist (§8). Deleting state.db must be recoverable by re-running `outpost apply`. The one thing here that is *not* a cache is desired run state: `outpost stop` records intent a running supervisor reconciles toward.

Index

Constants

View Source
const (
	DesiredRunning = "running"
	DesiredStopped = "stopped"
)

Desired run state for a service.

View Source
const (
	EventStarted    = "started"
	EventStopped    = "stopped"
	EventRestarted  = "restarted"
	EventExited     = "exited"
	EventHealthFail = "health-fail"
	EventHealthOK   = "health-ok"
	EventError      = "error"
	EventApply      = "apply"
	EventBackup     = "backup"
	EventRestore    = "restore"
)

Event kinds recorded in the activity feed.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	ID      int64
	Service string
	Kind    string
	Message string
	At      time.Time
}

Event is one entry in the rolling activity log.

type ServiceRecord

type ServiceRecord struct {
	Name         string
	Runtime      string
	Status       string
	InstanceID   string // PID for processes, container ID for containers
	Desired      string
	RestartEpoch int64
	RestartCount int
	// Halted is set when the supervisor has given up on a service per its
	// restart_policy. Only an explicit start or restart clears it.
	Halted        bool
	LastStartedAt time.Time
	UpdatedAt     time.Time
}

ServiceRecord is one row of observed service state.

type Store

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

Store is a SQLite-backed state store. It is safe for concurrent use.

func Open

func Open(path string) (*Store, error)

Open opens (creating if needed) the state database at path.

func (*Store) AppendEvent

func (s *Store) AppendEvent(service, kind, message string) error

AppendEvent records one activity-feed entry.

func (*Store) Close

func (s *Store) Close() error

func (*Store) DeleteService

func (s *Store) DeleteService(name string) error

DeleteService drops a service and its events, for services removed from the manifest.

func (*Store) Events

func (s *Store) Events(service string, limit int) ([]Event, error)

Events returns the most recent events first. An empty service means all services; limit <= 0 means no limit.

func (*Store) GetService

func (s *Store) GetService(name string) (ServiceRecord, bool, error)

GetService returns one record; ok is false when no such service is recorded.

func (*Store) ListServices

func (s *Store) ListServices() ([]ServiceRecord, error)

ListServices returns every recorded service, ordered by name.

func (*Store) PruneEvents

func (s *Store) PruneEvents(maxAge time.Duration, maxRows int) error

PruneEvents bounds the activity log by age and by total row count (§8).

func (*Store) RequestRestart

func (s *Store) RequestRestart(name string) error

RequestRestart bumps the restart epoch. A supervisor that sees an epoch newer than the one it last acted on restarts the service.

func (*Store) SetDesired

func (s *Store) SetDesired(name, desired string) error

SetDesired records that a service should be running or stopped, creating the row if the supervisor has not observed the service yet.

func (*Store) SetHalted

func (s *Store) SetHalted(name string, halted bool) error

SetHalted records that the supervisor has stopped trying to keep a service running, so `outpost status` can explain why nothing is happening.

func (*Store) UpsertService

func (s *Store) UpsertService(rec ServiceRecord) error

UpsertService records observed state, leaving desired state and the restart epoch — which belong to the CLI, not the supervisor — untouched.

Jump to

Keyboard shortcuts

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