daemon

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 47 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

Overview

Package daemon is the node daemon: it owns this machine's sandboxes and serves the local HTTP API on a unix socket in the state directory.

Index

Constants

View Source
const (
	DefaultCPUs     = backend.DefaultCPUs
	DefaultMemoryMB = backend.DefaultMemoryMB
	DefaultDiskGB   = backend.DefaultDiskGB
)

Defaults for a new sandbox's resources (#13).

View Source
const DefaultTokenTTL = time.Hour

DefaultTokenTTL is how long a join token is valid by default.

View Source
const DesktopPort = 0

DesktopPort reserves the non-TCP port 0 in the expose store for the agent's desktop service. It cannot collide with a sandbox web application's port.

View Source
const LockName = "daemon.lock"

LockName is the daemon lock's file name inside the state directory; the running daemon holds it open.

View Source
const LogName = "daemon.log"
View Source
const NoNetwork = "sandboxes have no network: the daemon is not running as root"

NoNetwork is the warning for Firecracker sandboxes of a daemon that is not root, which cannot create their tap devices and firewall rules.

View Source
const SocketName = "boxpool.sock"

SocketName is the API socket's file name inside the state directory.

View Source
const StateMissing backend.State = "missing"

StateMissing is the state of a sandbox whose record this node has but whose backend no longer knows it, e.g. after its container was deleted by hand. Removing it deletes the record.

View Source
const StateUnreachable backend.State = "unreachable"

StateUnreachable is the state the head lists a node's sandboxes in while the node misses heartbeats. The head keeps them; the node's next report replaces them.

View Source
const StoreName = "state.db"

StoreName is the sandbox database's file name inside the state directory.

Variables

This section is empty.

Functions

func Handler

func Handler(info Info, st *store.Store, d Driver) http.Handler

Handler returns the daemon's HTTP API. Without a driver, the sandbox endpoints answer 503.

func OpenLog

func OpenLog(dir string) (io.WriteCloser, error)

OpenLog keeps a bounded daemon log for both service and foreground runs.

func Run

func Run(ctx context.Context, dir string, info Info) (err error)

Run creates the state directory, takes the daemon lock, opens the sandbox store and the backend named by info.Backend (on Linux: firecracker or docker; on macOS: the Virtualization framework) and serves the API on the socket in dir until ctx is cancelled. Only one daemon may run per state directory. Shutdown cancels sessions and waits for every handler before releasing the store and lock. Cleanup may outlast shutdownTimeout when a backend operation cannot finish immediately after cancellation.

Types

type AccessToken

type AccessToken struct {
	ID        string    `json:"id"`
	Token     string    `json:"token,omitempty"`
	Scope     string    `json:"scope"`
	Sandbox   string    `json:"sandbox,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	ExpiresAt time.Time `json:"expires_at,omitzero"`
	LastUsed  time.Time `json:"last_used,omitzero"`
}

AccessToken is an access token as GET /v1/access-tokens lists it. Token, the secret, is set only in the answer to its creation. Revoke it with DELETE /v1/access-tokens/{id}.

type AccessTokenRequest

type AccessTokenRequest struct {
	Scope   string        `json:"scope"`
	Sandbox string        `json:"sandbox,omitempty"`
	TTL     time.Duration `json:"ttl_ns,omitempty"`
}

AccessTokenRequest is the body of POST /v1/access-tokens. Scope is one of auth.Scopes; Sandbox, if set, is the only sandbox the token reaches. A zero TTL never expires.

type CreateRequest

type CreateRequest struct {
	Name     string `json:"name,omitempty"`
	Image    string `json:"image,omitempty"`
	CPUs     int    `json:"cpu,omitempty"`
	MemoryMB int    `json:"mem_mb,omitempty"`
	DiskGB   int    `json:"disk_gb,omitempty"`
	// Restart is the restart policy of a new sandbox: "always" boots it
	// again when the daemon starts and finds it stopped though it was
	// running, as after a host reboot. "" or "no" means never.
	Restart string `json:"restart,omitempty"`
	// From is a snapshot to copy a new sandbox's disk from. Its disk is at
	// least the snapshot's size.
	From string `json:"from,omitempty"`
	// OS, Arch and Node constrain where the head places a new sandbox: the
	// node's OS (linux, darwin or macos) and architecture (amd64, arm64),
	// and a label it must have.
	OS   string `json:"os,omitempty"`
	Arch string `json:"arch,omitempty"`
	Node string `json:"node,omitempty"`
}

CreateRequest is the body of POST /v1/sandboxes. Zero fields get a generated name and the default resources.

type Driver

type Driver interface {
	backend.Driver
	Dial(ctx context.Context, id string) (net.Conn, error)
}

Driver is a backend that can also connect to the agent in a running sandbox, as both drivers do.

type Error

type Error struct {
	Message string `json:"message"`
}

Error is the body of every API error.

type Expose

type Expose struct {
	Sandbox   string    `json:"sandbox"`
	Port      int       `json:"port"`
	Public    bool      `json:"public,omitempty"`
	URL       string    `json:"url"`
	TokenID   string    `json:"token_id,omitempty"`
	CreatedAt time.Time `json:"created_at"`
}

Expose is a sandbox port the head serves at URL. Unless it is public, URL carries an expose token only in the answer to its creation: opening it swaps the token for a cookie. Revoking TokenID closes the URL.

type ExposeCheck

type ExposeCheck struct {
	Hostname string `json:"hostname"`
}

ExposeCheck describes the head's readiness to serve tailnet HTTPS URLs.

type ExposeRequest

type ExposeRequest struct {
	Sandbox string `json:"sandbox"`
	Port    int    `json:"port"`
	Public  bool   `json:"public,omitempty"`
	Desktop bool   `json:"desktop,omitempty"`
}

ExposeRequest is the body of POST /v1/exposes.

type Info

type Info struct {
	Version string `json:"version"`
	OS      string `json:"os"`
	Arch    string `json:"arch"`
	// StateDir holds the snapshots, in snapshots/; Run sets it.
	StateDir string `json:"state_dir"`
	Backend  string `json:"backend"`
	// PID is the serving daemon's process ID; Run sets it.
	PID int `json:"pid"`
	// Warning, if set, is about the backend, e.g. that it is a fallback with
	// weaker isolation. Commands that create sandboxes print it.
	Warning string `json:"warning,omitempty"`
	// AllowSleep opts out of macOS idle-sleep prevention.
	AllowSleep bool `json:"allow_sleep,omitempty"`
}

Info describes the daemon and the node it runs on.

type JoinPoolRequest

type JoinPoolRequest struct {
	Token string `json:"token"`
}

JoinPoolRequest is the body of POST /v1/pool/join.

type JoinPoolResponse

type JoinPoolResponse struct {
	ID   string `json:"id"`
	Head string `json:"head"`
}

JoinPoolResponse is this node's ID in the pool at Head.

type Labels

type Labels struct {
	Labels []string `json:"labels"`
}

Labels is the body of PUT /v1/labels: this machine's labels, which boxpool sh --node picks nodes by.

type Node

type Node struct {
	ID       string    `json:"id,omitempty"`
	Name     string    `json:"name"`
	Role     string    `json:"role"`
	OS       string    `json:"os"`
	Arch     string    `json:"arch"`
	JoinedAt time.Time `json:"joined_at,omitzero"`
	// State is ready, or unreachable while the node misses heartbeats.
	// CPUs and MemoryMB are free for new sandboxes, as it last reported.
	State         string    `json:"state"`
	Labels        []string  `json:"labels"`
	CPUs          int       `json:"cpu"`
	MemoryMB      int64     `json:"mem_mb"`
	SeenAt        time.Time `json:"seen_at,omitzero"`
	TotalCPUs     int       `json:"total_cpu,omitempty"`
	TotalMemoryMB int64     `json:"total_mem_mb,omitempty"`
	Warning       string    `json:"warning,omitempty"`
}

Node is a machine in the pool as GET /v1/nodes reports it. The head lists itself first, with role "head" and no ID.

type PromoteResponse

type PromoteResponse struct {
	Head string `json:"head"`
}

PromoteResponse is the body of POST /v1/pool/promote.

type RaftStatus

type RaftStatus struct {
	Leader  bool     `json:"leader"`
	Servers []string `json:"servers"` // node IDs
}

RaftStatus is the body of the pool API's GET /v1/pool/raft.

type ReplicaRequest

type ReplicaRequest struct {
	CA       []byte `json:"ca"`
	Key      []byte `json:"key"`
	Addr     string `json:"addr"`
	Admitter string `json:"admitter"`
}

ReplicaRequest is the body of POST /v1/pool/replica, which the head sends to a node through its tunnel: the head CA, its PKCS #8 key, the node's address as the head reaches it, and the head's node ID.

type Report

type Report struct {
	CPUs          int       `json:"cpu"`
	MemoryMB      int64     `json:"mem_mb"`
	Labels        []string  `json:"labels"`
	Sandboxes     []Sandbox `json:"sandboxes"`
	TotalCPUs     int       `json:"total_cpu,omitempty"`
	TotalMemoryMB int64     `json:"total_mem_mb,omitempty"`
	Warning       string    `json:"warning,omitempty"`
	// Port is the node's pool port, which the head sets Addr from, with the
	// host the report came from, for the node to serve as a replica.
	Port string `json:"pool_port,omitempty"`
	Addr string `json:"addr,omitempty"`
}

Report is the body of a node's heartbeat, POST /v1/heartbeat on the head. CPUs and MemoryMB are what a new sandbox could have, after the host reserve and existing sandboxes.

type Sandbox

type Sandbox struct {
	ID        string        `json:"id"`
	Name      string        `json:"name"`
	Backend   string        `json:"backend"`
	State     backend.State `json:"state"`
	CPUs      int           `json:"cpu"`
	MemoryMB  int           `json:"mem_mb"`
	DiskGB    int           `json:"disk_gb"`
	CreatedAt time.Time     `json:"created_at"`
	Restart   string        `json:"restart,omitempty"`
	// Warning is set by stop and remove when the sandbox did not shut down
	// cleanly (backend.ErrUncleanStop): it is stopped, but its disk may be
	// inconsistent. Pause sets it when it stopped the sandbox instead.
	Warning string `json:"warning,omitempty"`
	// Node is the name of the node the sandbox is on, when the head lists
	// another node's sandbox.
	Node string `json:"node,omitempty"`
	OS   string `json:"os,omitempty"`
}

Sandbox is a sandbox as the API reports it. State is the backend's live state when the sandbox is on this daemon's backend.

type Snapshot

type Snapshot struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	Backend   string    `json:"backend"`
	Sandbox   string    `json:"sandbox"`
	DiskGB    int       `json:"disk_gb"`
	CreatedAt time.Time `json:"created_at"`
	// Warning is set when the sandbox, stopped for the snapshot, did not
	// shut down cleanly, so the snapshot may be inconsistent.
	Warning string `json:"warning,omitempty"`
}

Snapshot is a named copy of a sandbox's disk, which new sandboxes on the same backend can start from. Sandbox is the source's name when it was taken.

type SnapshotRequest

type SnapshotRequest struct {
	Name string `json:"name"`
}

SnapshotRequest is the body of POST /v1/sandboxes/{name}/snapshot.

type Token

type Token struct {
	Token     string    `json:"token"`
	ExpiresAt time.Time `json:"expires_at"`
}

Token is a new join token. Revoke it with DELETE /v1/tokens/{hash}, where hash is auth.JoinToken.Hash.

type TokenRequest

type TokenRequest struct {
	TTL  time.Duration `json:"ttl_ns,omitempty"`
	Addr string        `json:"addr,omitempty"`
}

TokenRequest is the body of POST /v1/tokens. Zero fields get DefaultTokenTTL and this host's name with auth.JoinPort.

Jump to

Keyboard shortcuts

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