config

package
v0.3.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const ProjectFileName = "devrun.yaml"

Variables

This section is empty.

Functions

func ConfigDir

func ConfigDir() string

ConfigDir returns ~/.config/devrun (or $XDG_CONFIG_HOME/devrun).

func DaemonPIDPath

func DaemonPIDPath() string

func DataDir

func DataDir() string

DataDir returns ~/.local/share/devrun (or $XDG_DATA_HOME/devrun).

func LogPath

func LogPath(name string) string

func ReAdoptServices

func ReAdoptServices(services map[string]*ServiceState)

ReAdoptServices checks each service's PID to determine if it is still alive. Alive → StatusRunning + ReAdopted=true. Dead → StatusCrashed, PID cleared. Modifies the map in place. Only checks services that have a non-nil PID.

func RegistryPath

func RegistryPath() string

func Resolve

func Resolve(dir string, global bool) (*Registry, Source, error)

Resolve determines which service registry is active for a command run in dir.

When global is false and dir contains a devrun.yaml, that file is loaded and converted to an in-memory Registry, and the returned Source points at it. Otherwise the global registry (~/.config/devrun/services.yaml) is returned with an empty Source. Project services are never written to the global registry, so it contains only services registered with `devrun add`.

func SaveProject

func SaveProject(dir string, p *ProjectConfig) error

SaveProject writes p to devrun.yaml in dir. The file is re-marshalled from the in-memory structure, so hand-written comments and key ordering are not preserved.

func SaveRegistry

func SaveRegistry(path string, reg *Registry) error

SaveRegistry writes the registry to path, creating parent directories as needed.

func SaveState

func SaveState(path string, s *State) error

SaveState writes state atomically: write to .tmp, then rename.

func SocketPath

func SocketPath() string

func StatePath

func StatePath() string

Types

type ProjectConfig

type ProjectConfig struct {
	Name     string                           `yaml:"name,omitempty"`
	Services map[string]*ProjectServiceConfig `yaml:"services"`
}

ProjectConfig is the top-level structure of devrun.yaml.

func LoadProject

func LoadProject(dir string) (*ProjectConfig, error)

LoadProject reads devrun.yaml from dir. Returns nil, nil if the file does not exist. If Name is empty it defaults to the sanitised base name of dir.

func (*ProjectConfig) ToServiceConfigs

func (p *ProjectConfig) ToServiceConfigs(dir string) map[string]*ServiceConfig

ToServiceConfigs converts a ProjectConfig to ServiceConfig entries ready for the global registry. Relative CWD values are resolved against dir.

type ProjectServiceConfig

type ProjectServiceConfig struct {
	Command string            `yaml:"command"`
	CWD     string            `yaml:"cwd,omitempty"`
	Env     map[string]string `yaml:"env,omitempty"`
	Desc    string            `yaml:"desc,omitempty"`
}

ProjectServiceConfig is a service entry in a devrun.yaml file.

func (*ProjectServiceConfig) Validate

func (c *ProjectServiceConfig) Validate() error

Validate mirrors ServiceConfig.Validate for a devrun.yaml service entry.

type Registry

type Registry struct {
	Version  string                    `yaml:"version"`
	Services map[string]*ServiceConfig `yaml:"services"`
}

Registry is the top-level structure of services.yaml.

func LoadRegistry

func LoadRegistry(path string) (*Registry, error)

LoadRegistry reads services.yaml. Returns an empty registry if the file does not exist.

type ServiceConfig

type ServiceConfig struct {
	Name    string            `yaml:"name" json:"name"`
	Command string            `yaml:"command" json:"command"`
	CWD     string            `yaml:"cwd,omitempty" json:"cwd,omitempty"`
	Group   string            `yaml:"group,omitempty" json:"group,omitempty"`
	Env     map[string]string `yaml:"env,omitempty" json:"env,omitempty"`
	Desc    string            `yaml:"desc,omitempty" json:"desc,omitempty"`
}

ServiceConfig is the shared vocabulary across CLI, daemon, and config layer. YAML tags match the devrun.yaml and services.yaml schema. JSON tags are load bearing too: ServiceConfig crosses the wire as JSON in ipc.StartPayload and in the daemon re-exec handoff, so the field names must be pinned explicitly rather than left to default to the Go identifiers.

func (*ServiceConfig) Validate

func (c *ServiceConfig) Validate() error

Validate reports whether a service definition is runnable. The dominant failure is a blank command: the daemon would otherwise hand `sh -c` an empty script, which exits 0 immediately and is reported as a clean one-shot run.

type ServiceState

type ServiceState struct {
	Status       ServiceStatus `json:"state"`
	PID          *int          `json:"pid"`
	Port         *int          `json:"port"`
	StartedAt    *time.Time    `json:"started_at"`
	LastExitCode *int          `json:"last_exit_code"`
	ReAdopted    bool          `json:"re_adopted"`
}

type ServiceStatus

type ServiceStatus string
const (
	StatusStopped  ServiceStatus = "stopped"
	StatusStarting ServiceStatus = "starting"
	StatusRunning  ServiceStatus = "running"
	StatusCrashed  ServiceStatus = "crashed"
	StatusStopping ServiceStatus = "stopping"
	// StatusExited marks a process that terminated on its own with exit code 0
	// (e.g. a one-shot command), as opposed to StatusCrashed (non-zero exit or
	// killed by signal) or StatusStopped (terminated by `devrun stop`).
	StatusExited ServiceStatus = "exited"
)

func (ServiceStatus) IsLive

func (s ServiceStatus) IsLive() bool

IsLive reports whether the process is (or should be) running — i.e. uptime, CPU, and memory are meaningful. Terminal states (stopped, exited, crashed) are not live.

type Source

type Source struct {
	// Local is the path to the project devrun.yaml when one is active, or "" when
	// the global registry is in use.
	Local string
	// Dir is the directory the project devrun.yaml lives in. Empty for the global
	// registry.
	Dir string
}

Source describes where the active service registry for a command came from.

func (Source) IsLocal

func (s Source) IsLocal() bool

IsLocal reports whether a project devrun.yaml is the active config.

type State

type State struct {
	Version  int                      `json:"version"`
	Services map[string]*ServiceState `json:"services"`
}

func LoadState

func LoadState(path string) (*State, error)

LoadState reads state.json. Returns an empty state if the file does not exist.

Jump to

Keyboard shortcuts

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