state

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseDir

func BaseDir() string

BaseDir returns the base gridctl directory (~/.gridctl/).

func CheckAndClean

func CheckAndClean(name string) (bool, error)

CheckAndClean checks if a state file exists and if the process is running. If the process is dead, it removes the state file and returns true (cleaned). If the process is running, it returns false (not cleaned). If no state file exists, it returns false.

func Delete

func Delete(name string) error

Delete removes a state file.

func EnsureLogDir

func EnsureLogDir() error

EnsureLogDir creates the log directory if it doesn't exist.

func EnsureTelemetryServerDir

func EnsureTelemetryServerDir(stackName, serverName string) error

EnsureTelemetryServerDir creates the per-server telemetry directory with mode 0700, matching the vault/state convention. Any new directories on the path inherit the same restrictive permissions because lumberjack will not chmod them on its own.

func FindOrphan

func FindOrphan(port int) (int, bool, error)

FindOrphan looks for an orphan gridctl daemon listening on port — a process that owns the port but has no managed state file (because e.g. an earlier shutdown deleted state mid-way, or the daemon was started in a mode that doesn't write state, like 'serve --foreground').

Returns (pid, true, nil) only when all three signals agree:

  1. The /health endpoint on port responds 200.
  2. Exactly one process (after excluding our own PID) holds the TCP listen socket for that port.
  3. That process's executable basename is "gridctl".

Any ambiguity — health probe fails, no listener, multiple listeners after self-exclusion, or executable name mismatch — returns ok=false so the caller falls through to the legacy behavior rather than acting on guesswork.

func IsRunning

func IsRunning(state *DaemonState) bool

IsRunning checks if the daemon process is still running.

func KillDaemon

func KillDaemon(state *DaemonState) error

KillDaemon sends SIGTERM to the daemon process, waits up to 5 seconds for graceful shutdown, then sends SIGKILL if the process is still running.

func LockPath

func LockPath(name string) string

LockPath returns the path to a lock file for a stack.

func LogDir

func LogDir() string

LogDir returns the directory for log files (~/.gridctl/logs/).

func LogPath

func LogPath(name string) string

LogPath returns the path to a log file for a stack.

func PinsDir

func PinsDir() string

PinsDir returns the directory for schema pin files (~/.gridctl/pins/).

func PinsPath

func PinsPath(name string) string

PinsPath returns the path to the pin file for a stack (~/.gridctl/pins/{name}.json).

func Save

func Save(state *DaemonState) error

Save writes a daemon state file.

func SkillPinsPath

func SkillPinsPath(name string) string

SkillPinsPath returns the path to the skill pin file for a stack (~/.gridctl/pins/skills/{name}.json). A subdirectory, not a filename suffix, keeps the namespace disjoint from tool pins: any suffix scheme inside PinsDir would collide with a stack literally named with that suffix (PinsPath("x.skills") == a suffix-based SkillPinsPath("x")). Skill pins track registry documents, not live tool sets, and the two stores version independently.

func StacksDir

func StacksDir() string

StacksDir returns the directory for saved stack files (~/.gridctl/stacks/).

func StateDir

func StateDir() string

StateDir returns the directory for state files (~/.gridctl/state/).

func StatePath

func StatePath(name string) string

StatePath returns the path to a state file for a stack.

func TelemetryDir

func TelemetryDir() string

TelemetryDir returns the root directory for opt-in telemetry persistence (~/.gridctl/telemetry/). Subtree layout: <stack>/<server>/{logs,metrics,traces}.jsonl.

func TelemetryServerDir

func TelemetryServerDir(stackName, serverName string) string

TelemetryServerDir returns the per-server directory under TelemetryDir for the given stack and server.

func TelemetryServerPath

func TelemetryServerPath(stackName, serverName, signal string) string

TelemetryServerPath returns the path to a single signal file for a server. signal must be "logs", "metrics", or "traces"; any string is accepted but only those three are produced by the daemon.

func VaultDir

func VaultDir() string

VaultDir returns the directory for vault storage (~/.gridctl/vault/).

func VerifyPID

func VerifyPID(pid int) bool

VerifyPID checks if a process with the given PID is running.

func WithLock

func WithLock(name string, timeout time.Duration, fn func() error) error

WithLock executes fn while holding an exclusive lock on the stack state. Returns error if lock cannot be acquired within timeout.

Types

type DaemonState

type DaemonState struct {
	StackName string    `json:"stack_name"`
	StackFile string    `json:"stack_file"`
	PID       int       `json:"pid"`
	Port      int       `json:"port"`
	StartedAt time.Time `json:"started_at"`

	// AuthToken and AuthHeader carry the gateway's inbound credentials so
	// local subcommands can authenticate against the API they already know
	// the port of. Empty when gateway.auth is not configured.
	//
	// The daemon records the token already resolved, because the config
	// loader expands ${VAR} references before the value reaches it. The
	// alternative — each subcommand loading the stack and expanding it —
	// would turn a `gridctl status` into a vault passphrase prompt.
	//
	// This does place a resolved secret on disk. The state file is written
	// 0600 (see SaveDaemonState), matching the vault's own plaintext
	// secrets.json and the machine key in pkg/mcpauth, so it is consistent
	// with the existing posture rather than a new exposure.
	AuthToken  string `json:"auth_token,omitempty"`
	AuthHeader string `json:"auth_header,omitempty"`
	AuthType   string `json:"auth_type,omitempty"`
}

DaemonState represents the state of a running daemon.

func List

func List() ([]DaemonState, error)

List returns all daemon states.

func Load

func Load(name string) (*DaemonState, error)

Load reads a daemon state file.

Jump to

Keyboard shortcuts

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