lifecycle

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 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
	// Forget drops a remembered stopped instance so it no longer appears on
	// the dashboard. Only registry-backed (fully stopped standalone)
	// instances have an entry; anything else is discovery.ErrNotFound.
	Forget(ctx context.Context, key string) 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) 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.

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