state

package
v0.38.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package state manages persistent devrig project state in .devrig/state.json.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Remove

func Remove(stateDir string) error

Remove deletes state.json and attempts to remove the state directory if empty.

func StateDir

func StateDir(configPath string) string

StateDir returns the .devrig directory for a project (next to devrig.toml).

func UpdateServiceExit

func UpdateServiceExit(stateDir, service string, code int)

UpdateServiceExit writes the exit code for a service.

func UpdateServicePhase

func UpdateServicePhase(stateDir, service, phase string)

UpdateServicePhase writes the phase field for a service.

func UpdateServiceProc added in v0.34.3

func UpdateServiceProc(stateDir, service string, pid uint32, startTimeMs int64)

UpdateServiceProc writes the PID and process start time for a service into state.json using an exclusive file lock.

Types

type AddonState

type AddonState struct {
	AddonType   string    `json:"addon_type"`
	Namespace   string    `json:"namespace"`
	InstalledAt time.Time `json:"installed_at"`
}

type ClusterDeployState

type ClusterDeployState struct {
	ImageTag     string    `json:"image_tag"`
	LastDeployed time.Time `json:"last_deployed"`
}

type ClusterState

type ClusterState struct {
	ClusterName      string                        `json:"cluster_name"`
	KubeconfigPath   string                        `json:"kubeconfig_path"`
	RegistryName     *string                       `json:"registry_name,omitempty"`
	RegistryPort     *uint16                       `json:"registry_port,omitempty"`
	DeployedServices map[string]ClusterDeployState `json:"deployed_services"`
	InstalledAddons  map[string]AddonState         `json:"installed_addons"`
	// K3dVersion is the version of the k3d binary that created/last started the
	// cluster, used to detect version skew on reuse (see cluster.Manager.Ensure).
	K3dVersion string `json:"k3d_version,omitempty"`
}

type ComposeServiceState

type ComposeServiceState struct {
	ContainerID   string  `json:"container_id"`
	ContainerName string  `json:"container_name"`
	Port          *uint16 `json:"port,omitempty"`
}

type DashboardState

type DashboardState struct {
	DashboardPort uint16 `json:"dashboard_port"`
	GRPCPort      uint16 `json:"grpc_port"`
	HTTPPort      uint16 `json:"http_port"`
}

type DockerState

type DockerState struct {
	ContainerID     string            `json:"container_id"`
	ContainerName   string            `json:"container_name"`
	Port            *uint16           `json:"port,omitempty"`
	PortAuto        bool              `json:"port_auto"`
	Protocol        *string           `json:"protocol,omitempty"`
	NamedPorts      map[string]uint16 `json:"named_ports"`
	InitCompleted   bool              `json:"init_completed"`
	InitCompletedAt *time.Time        `json:"init_completed_at,omitempty"`
}

type ProjectState

type ProjectState struct {
	Slug            string                         `json:"slug"`
	ConfigPath      string                         `json:"config_path"`
	StartedAt       time.Time                      `json:"started_at"`
	Services        map[string]ServiceState        `json:"services"`
	Docker          map[string]DockerState         `json:"docker"`
	ComposeServices map[string]ComposeServiceState `json:"compose_services"`
	NetworkName     *string                        `json:"network_name,omitempty"`
	Cluster         *ClusterState                  `json:"cluster,omitempty"`
	Dashboard       *DashboardState                `json:"dashboard,omitempty"`
	// PID of the main devrig process (written so `devrig stop` can signal it).
	PID int `json:"pid,omitempty"`
	// PIDStartTimeMs is the devrig process's creation time (ms since epoch),
	// stored so `devrig stop` can confirm the PID hasn't been reused before
	// signalling it.
	PIDStartTimeMs int64 `json:"pid_start_time_ms,omitempty"`
}

ProjectState is serialised to .devrig/state.json.

func Load

func Load(stateDir string) *ProjectState

Load reads state.json from stateDir. Returns nil if it doesn't exist or can't be parsed.

func (*ProjectState) Save

func (s *ProjectState) Save(stateDir string) error

Save writes state to state.json atomically (tmp → rename).

type ServiceState

type ServiceState struct {
	PID uint32 `json:"pid"`
	// StartTimeMs is the service process's creation time (ms since epoch),
	// recorded alongside PID so a later run can reuse-proof identify and reap an
	// orphan left by a crashed devrig.
	StartTimeMs int64   `json:"start_time_ms,omitempty"`
	Port        *uint16 `json:"port,omitempty"`
	PortAuto    bool    `json:"port_auto"`
	Protocol    *string `json:"protocol,omitempty"`
	Phase       *string `json:"phase,omitempty"`
	ExitCode    *int    `json:"exit_code,omitempty"`
}

Jump to

Keyboard shortcuts

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