lifecycle

package
v0.0.17 Latest Latest
Warning

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

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

Documentation

Overview

Package lifecycle starts, stops and restarts discovered Dapr applications and their sidecars. Compose instances act on containers via the container runtime; standalone (dapr run) instances signal processes and re-run captured commands. An in-memory registry keeps standalone instances the dashboard stopped visible until they are started again.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTarget      = errors.New("invalid target")
	ErrInvalidAction      = errors.New("invalid action")
	ErrUnsupported        = errors.New("action not supported for this app")
	ErrRuntimeUnavailable = errors.New("no container runtime available")
)

Functions

func Overlay

func Overlay(inner discovery.Service, reg *Registry, proc ProcController) discovery.Service

Overlay decorates a discovery.Service with the stopped-app registry: partially stopped live instances get their statuses corrected, and fully stopped instances (invisible to the process scan) are appended from their stop-time snapshots. Compose instances never hit the registry — stopped containers are discovered natively.

func ValidAction

func ValidAction(a Action) bool

func ValidTarget

func ValidTarget(t Target) bool

Types

type Action

type Action string

Action is the lifecycle operation.

const (
	ActionStart   Action = "start"
	ActionStop    Action = "stop"
	ActionRestart Action = "restart"
)

type Entry

type Entry struct {
	Instance discovery.Instance
	Procs    map[Target]ProcSnapshot
}

Entry is one stopped (fully or partially) standalone instance.

type Manager

type Manager interface {
	Do(ctx context.Context, key string, target Target, action Action) error
	// Dismiss hides an inactive instance from the dashboard: it drops any
	// registry ghost and suppresses the InstanceKey so a natively-scanned
	// stopped instance (e.g. a stopped compose container) stops appearing.
	// The suppression auto-clears when the instance is seen running again.
	// It always succeeds and never touches Docker.
	Dismiss(ctx context.Context, key string) error
	// ClearInactive dismisses every currently fully-stopped instance and
	// returns how many distinct instances were dismissed.
	ClearInactive(ctx context.Context) (int, error)
}

Manager starts, stops and restarts discovered app instances.

func New

New builds the Manager. run may be nil (no container runtime): compose actions then fail with ErrRuntimeUnavailable.

type ProcController

type ProcController interface {
	Snapshot(pid int) (ProcSnapshot, error)
	Terminate(pid int) error
	Kill(pid int) error
	Alive(pid int) bool
}

ProcController isolates OS process operations so the manager is testable.

func NewProcController

func NewProcController() ProcController

NewProcController returns the gopsutil-backed ProcController.

type ProcSnapshot

type ProcSnapshot struct {
	PID     int
	Argv    []string
	Dir     string
	LogPath string // stdout/stderr destination for the re-run; "" discards
}

ProcSnapshot captures what is needed to re-run a stopped process.

type Registry

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

Registry is the in-memory record of instances the dashboard stopped. It is intentionally not persisted: after a dashboard restart the processes are genuinely gone and unknowable.

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Drop

func (r *Registry) Drop(key string)

Drop removes the whole entry.

func (*Registry) DropTarget

func (r *Registry) DropTarget(key string, t Target)

DropTarget removes one target's snapshot; the entry disappears with its last target.

func (*Registry) Get

func (r *Registry) Get(key string) (Entry, bool)

Get resolves key by InstanceKey first, then by AppID (first match, sorted).

func (*Registry) IsSuppressed added in v0.0.17

func (r *Registry) IsSuppressed(key string) bool

IsSuppressed reports whether key is currently suppressed.

func (*Registry) List

func (r *Registry) List() []Entry

List returns all entries sorted by InstanceKey.

func (*Registry) RecordStop

func (r *Registry) RecordStop(in discovery.Instance, snaps map[Target]ProcSnapshot)

RecordStop merges snaps into the entry for in's InstanceKey, storing in as the display snapshot.

func (*Registry) Suppress added in v0.0.17

func (r *Registry) Suppress(key string)

Suppress hides an InstanceKey from the overlay while it remains fully stopped. It is cleared automatically when the instance is seen running again (see overlay.List) or on dashboard restart (the set is not persisted).

func (*Registry) Unsuppress added in v0.0.17

func (r *Registry) Unsuppress(key string)

Unsuppress removes a key from the suppression set.

type Starter

type Starter interface {
	Start(argv []string, dir, logPath string) error
}

Starter launches a captured command detached from the dashboard process.

func NewStarter

func NewStarter() Starter

NewStarter returns the exec-backed Starter.

type Target

type Target string

Target selects which half of an instance an action applies to.

const (
	TargetApp   Target = "app"
	TargetDaprd Target = "daprd"
	TargetAll   Target = "all"
)

Jump to

Keyboard shortcuts

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