runtime

package
v0.11.5 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: GPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LabelManaged = "cashpilot.managed"
	LabelService = "cashpilot.service"
	LabelVersion = "cashpilot.version"
	LabelRuntime = "cashpilot.runtime"
)
View Source
const NativeRuntimeKind = "native"

NativeRuntimeKind is the runtime-kind key the NativeProcessProvider registers under in the services manager. A service that declares a native binary for the host is routed onto this runtime; image-only services stay on Docker.

Variables

This section is empty.

Functions

func DeviceHostname added in v0.11.0

func DeviceHostname() string

DeviceHostname returns this machine's hostname for {hostname} expansion, falling back to "desktop" when the OS can't report one. Exported so the app layer can offer the same value as the form default the deploy path will substitute.

Types

type ContainerInfo

type ContainerInfo struct {
	Slug        string  `json:"slug"`
	ContainerID string  `json:"containerId"`
	Name        string  `json:"name"`
	Image       string  `json:"image"`
	Status      string  `json:"status"`
	CPUPercent  float64 `json:"cpuPercent"`
	MemoryMB    float64 `json:"memoryMb"`
}

type DeploySpec

type DeploySpec struct {
	Slug    string
	Service catalog.Service
	Env     map[string]string
}

type DockerProvider

type DockerProvider struct{}

func NewDockerProvider

func NewDockerProvider() *DockerProvider

func (*DockerProvider) Deploy

func (p *DockerProvider) Deploy(ctx context.Context, spec DeploySpec, progress func(string)) (ContainerInfo, error)

func (*DockerProvider) List

func (p *DockerProvider) List(ctx context.Context) ([]ContainerInfo, error)

func (*DockerProvider) Logs

func (p *DockerProvider) Logs(ctx context.Context, slug string, lines int) (string, error)

func (*DockerProvider) Remove

func (p *DockerProvider) Remove(ctx context.Context, slug string) error

func (*DockerProvider) Restart

func (p *DockerProvider) Restart(ctx context.Context, slug string) error

func (*DockerProvider) Start added in v0.6.0

func (p *DockerProvider) Start(ctx context.Context, slug string) error

func (*DockerProvider) Status

func (p *DockerProvider) Status(ctx context.Context) Status

func (*DockerProvider) Stop

func (p *DockerProvider) Stop(ctx context.Context, slug string) error

type InstallGuide

type InstallGuide struct {
	ID          string   `json:"id"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Platforms   []string `json:"platforms"`
	URL         string   `json:"url"`
	Commands    []string `json:"commands"`
	Notes       []string `json:"notes"`
}

func InstallGuides

func InstallGuides() []InstallGuide

func (InstallGuide) Supports added in v0.4.4

func (g InstallGuide) Supports(osName string) bool

type ManagedRuntimePlan

type ManagedRuntimePlan struct {
	Summary   string   `json:"summary"`
	Phases    []string `json:"phases"`
	Risks     []string `json:"risks"`
	Providers []string `json:"providers"`
}

func ManagedRuntimeRoadmap

func ManagedRuntimeRoadmap() ManagedRuntimePlan

type NativeProcessProvider added in v0.10.0

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

NativeProcessProvider runs catalog services as supervised native child processes, with no container runtime. It downloads each service's SHA-256-pinned binary over HTTPS, verifies it (fail-closed on mismatch or a missing/invalid checksum), extracts it under <appDir>/native/<slug>/, and launches it with an argv built from the service's native.command via the same shell-safe tokenizeCommand/substitute path Docker uses. stdout+stderr are captured to a bounded rotating log; a supervisor goroutine restarts a crashed process with bounded backoff (the native equivalent of Docker's restart policy). A JSON registry at <appDir>/native/state.json records each managed process (pid, binary, args, source url/sha, startedAt, desired state) so List/Start/Stop/Remove survive an app restart.

It implements runtime.Provider. ContainerInfo fields are repurposed for a process: ContainerID is the pid, Image is the source binary URL, Status is running/stopped, and CPU/memory come from gopsutil best-effort.

func NewNativeProcessProvider added in v0.10.0

func NewNativeProcessProvider(appDir string) *NativeProcessProvider

NewNativeProcessProvider builds a provider rooted at <appDir>/native with production defaults.

func (*NativeProcessProvider) Deploy added in v0.10.0

func (p *NativeProcessProvider) Deploy(ctx context.Context, spec DeploySpec, progress func(string)) (ContainerInfo, error)

Deploy downloads+verifies+extracts the service's native binary for this host and launches it as a supervised process. It mirrors DockerProvider.Deploy's shape (progress callbacks, redeploy replaces a prior instance) but targets a native process instead of a container.

func (*NativeProcessProvider) List added in v0.10.0

List reports every registry entry as a ContainerInfo, checking each recorded pid's liveness (and best-effort CPU/memory) via gopsutil. A process that isn't reachable reports zeros and status "stopped"; it never panics on a dead/reused pid.

Alive entries are sampled CONCURRENTLY (mirroring DockerProvider.statsForContainers): each goroutine owns its own out[i] slot, so no locking/shared map is needed, and a buffered semaphore bounds how many statFn calls run at once. A serial loop would make this O(N * cpuStatInterval); with the fan-out the added latency stays ~one interval regardless of N. Stopped entries are written synchronously (no sampling needed), and the result stays sorted by slug just like the previous serial loop.

func (*NativeProcessProvider) Logs added in v0.10.0

func (p *NativeProcessProvider) Logs(ctx context.Context, slug string, lines int) (string, error)

Logs returns the tail of the service's captured stdout+stderr, reading the rotated previous generation then the current one, bounded so a huge log cannot be loaded in full. An absent log yields an empty string (not an error).

func (*NativeProcessProvider) Remove added in v0.10.0

func (p *NativeProcessProvider) Remove(ctx context.Context, slug string) error

Remove stops the service, deletes its per-slug directory (binary + logs), and drops its registry entry — the native analogue of removing a container and its volumes.

func (*NativeProcessProvider) Restart added in v0.10.0

func (p *NativeProcessProvider) Restart(ctx context.Context, slug string) error

Restart stops then starts the service.

func (*NativeProcessProvider) SetEventRecorder added in v0.10.0

func (p *NativeProcessProvider) SetEventRecorder(fn func(slug, event, detail string))

SetEventRecorder wires a lifecycle-event sink (typically store.RecordEvent) so the supervisor's autonomous crashes and respawns are recorded into the same event stream HealthScores aggregates. Call once at wiring time, before the first Deploy — it is read (without locking) only from supervise goroutines, which are created later by Deploy.

func (*NativeProcessProvider) Start added in v0.10.0

func (p *NativeProcessProvider) Start(ctx context.Context, slug string) error

Start (re)launches a previously-deployed service from the registry. It is a no-op if the service is already running (as our child or as a live orphan pid).

func (*NativeProcessProvider) Status added in v0.10.0

Status reports the native runtime as always available: unlike Docker it has no external dependency (no daemon/socket), so it can always run a native process.

func (*NativeProcessProvider) Stop added in v0.10.0

func (p *NativeProcessProvider) Stop(ctx context.Context, slug string) error

Stop stops the service: a managed child is signalled gracefully then killed after the grace period; an orphan pid recorded by a previous session is signalled by pid. It marks the registry entry as desired=stopped so List reports it stopped.

type Provider

type Provider interface {
	Status(ctx context.Context) Status
	Deploy(ctx context.Context, spec DeploySpec, progress func(string)) (ContainerInfo, error)
	Start(ctx context.Context, slug string) error
	Stop(ctx context.Context, slug string) error
	Restart(ctx context.Context, slug string) error
	Remove(ctx context.Context, slug string) error
	Logs(ctx context.Context, slug string, lines int) (string, error)
	List(ctx context.Context) ([]ContainerInfo, error)
}

type Status

type Status struct {
	Available bool `json:"available"`
	// NativeAvailable reports whether the always-on native process runtime is
	// registered (and therefore available: it has no external dependency, no daemon
	// or socket to reach). It is an ADDITIVE signal set by the app layer from the
	// services manager — Available keeps its Docker-only meaning, which other code
	// still reads — so onboarding can proceed on Docker OR native.
	NativeAvailable bool              `json:"nativeAvailable"`
	Kind            string            `json:"kind"`
	Message         string            `json:"message"`
	Version         string            `json:"version"`
	Context         string            `json:"context"`
	Tools           map[string]string `json:"tools"`
}

Jump to

Keyboard shortcuts

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