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
- type Event
- type ServiceRecord
- type Store
- func (s *Store) AppendEvent(service, kind, message string) error
- func (s *Store) Close() error
- func (s *Store) DeleteService(name string) error
- func (s *Store) Events(service string, limit int) ([]Event, error)
- func (s *Store) GetService(name string) (ServiceRecord, bool, error)
- func (s *Store) ListServices() ([]ServiceRecord, error)
- func (s *Store) PruneEvents(maxAge time.Duration, maxRows int) error
- func (s *Store) RequestRestart(name string) error
- func (s *Store) SetDesired(name, desired string) error
- func (s *Store) SetHalted(name string, halted bool) error
- func (s *Store) UpsertService(rec ServiceRecord) error
Constants ¶
const ( DesiredRunning = "running" DesiredStopped = "stopped" )
Desired run state for a service.
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 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 (*Store) AppendEvent ¶
AppendEvent records one activity-feed entry.
func (*Store) DeleteService ¶
DeleteService drops a service and its events, for services removed from the manifest.
func (*Store) Events ¶
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 ¶
PruneEvents bounds the activity log by age and by total row count (§8).
func (*Store) RequestRestart ¶
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 ¶
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 ¶
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.