daemon

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 29 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 runs drives for one user, outside any session. Each drive is its own `f10 drive --foreground` child in the client's directory and environment, so leases and crash recovery stay the drive's own.

Index

Constants

View Source
const (
	ReasonUpgrade = "upgrade" // the next daemon resumes it
	ReasonStopped = "stopped" // f10 daemon stop: it waits for its next run
	ReasonResumed = "resumed" // this daemon started it again
)

Why a drive exited ExitDrained or ExitResume.

View Source
const APIVersion = 1

APIVersion is the control-plane API version this binary serves and calls; it rises only when a v2 package lands.

View Source
const ExitDrained = 6

ExitDrained is a drive's exit when it stopped for an upgrade.

View Source
const ExitNothingWatched = 7

ExitNothingWatched is a pass's exit when the project has no task left to watch: the daemon stops watching it.

View Source
const ExitResume = 8

ExitResume is a drive's exit when an answer came as it stopped: the daemon that runs it starts it again with --resume.

View Source
const NumberFileEnv = "F10_DRIVE_FILE"

NumberFileEnv names the file a drive the daemon runs writes its record number to, once the record is open.

View Source
const ResumeEnv = "F10_DRIVE_RESUMES"

ResumeEnv is set on every drive a daemon runs that starts an ExitResume again. A drive under an older daemon, which lacks it, names the --resume command instead of exiting for a restart that never comes.

View Source
const SocketURL = "http://f10-daemon"

SocketURL is the base every call on the socket goes to; the host is a placeholder, since the transport dials the socket whatever it names.

View Source
const Supported = false

Supported reports whether this platform runs a daemon; elsewhere drive runs in the foreground.

Variables

View Source
var ErrNotRunning = errors.New("no f10 daemon is running")

ErrNotRunning is a socket nobody listens on.

View Source
var ErrRunning = errors.New("an f10 daemon is already running")

ErrRunning is a second daemon finding the first one running.

View Source
var ErrStopping = errors.New("the daemon is stopping: run the command again")

ErrStopping is a drive refused because a stop drains the daemon.

Functions

func APIError added in v0.62.0

func APIError(info Info, version string) error

APIError is a daemon kept by the release rule whose API this client does not speak: the two say so instead of failing on a decode.

func DriveEnv added in v0.58.0

func DriveEnv(environ, extra []string) []string

func ExitPath

func ExitPath(log string) string

ExitPath is the file holding a drive log's exit, once its process ended.

func FindLog

func FindLog(string, string, int) string

FindLog finds nothing: no daemon wrote one.

func IsLocal added in v0.62.0

func IsLocal(req connect.AnyRequest) bool

IsLocal reports whether req came over the unix socket, or from this process: a unix socket's peer has no network address.

func LocalEnv added in v0.62.0

func LocalEnv(req connect.AnyRequest, env []string) []string

LocalEnv is the environment a request passes, honored only from the unix socket; a request from any other listener runs under the daemon's session.

func LogPath

func LogPath(dir string) string

LogPath is the daemon's own log.

func Newer

func Newer(a, b string) bool

Newer reports a strictly newer than b, both release versions (`0.46.0`, `v0.46.0`); a development build is newer than nothing, and nothing is newer than it, so it is replaced only by `f10 daemon stop`.

func RunDir

func RunDir() string

RunDir holds the socket, the locks, the logs and the drained runs: F10_RUN_DIR, else $XDG_RUNTIME_DIR/f10, else ~/.f10/run.

func SocketHTTP added in v0.62.0

func SocketHTTP(dir string) *http.Client

SocketHTTP is an HTTP client whose every request goes to the socket in dir.

func SocketPath

func SocketPath(dir string) string

SocketPath is where the daemon listens.

func Stop added in v0.62.0

func Stop(ctx context.Context, dir string, drain, upgrade bool) error

Stop stops the daemon in dir: drain lets each drive reach its next tick, and upgrade hands the drained drives to the next daemon.

func WatchProject added in v0.62.0

func WatchProject(ctx context.Context, runDir, root, dir string, env []string) (string, error)

WatchProject hands the project at root, its main checkout dir, to the daemon's watch passes, and returns the pass log.

func WithCaller added in v0.62.0

func WithCaller(ctx context.Context, c Caller) context.Context

WithCaller marks ctx as a call by c, which the tailnet's token check does so Hello can say what the caller may call without this package knowing tokens.

Types

type Caller added in v0.62.0

type Caller struct {
	Token      string
	Scopes     []string
	Procedures []string
}

A Caller is who makes a call on the tailnet: the device token's name, its scopes and the procedures they allow. A call with none in its context came over the unix socket, where every procedure is allowed.

func CallerOf added in v0.62.0

func CallerOf(ctx context.Context) (Caller, bool)

CallerOf is the caller WithCaller set, and false for a local call.

type Client added in v0.62.0

type Client struct {
	Dir    string
	Daemon f10v1connect.DaemonServiceClient
	Runs   f10v1connect.RunServiceClient
}

A Client calls the daemon listening in a run dir.

func Dial added in v0.62.0

func Dial(dir string) *Client

Dial is the client of the daemon in dir; nothing is dialled until a call.

type DriveCall added in v0.62.0

type DriveCall struct {
	Args   []string // the drive's arguments, as f10 drive takes them
	Dir    string   // where the drive was typed
	Env    []string // the allowlisted environment
	Resume int      // the record --resume names
}

A DriveCall is one drive for the daemon to run, or to attach to.

func ResumeCall added in v0.62.0

func ResumeCall(dir string, env []string, n int) DriveCall

ResumeCall is the call that picks drive n up again.

type DriveSpec added in v0.62.0

type DriveSpec struct {
	Argv   []string
	Dir    string
	Root   string
	Env    []string
	Resume int
}

A DriveSpec is one drive to run: its arguments, where it was typed, its project's storage root, its environment, and the record a resume names.

type Ensurer

type Ensurer struct {
	Dir, Version         string
	Spawn                func(context.Context) error
	Follow               bool
	Draining, Kept       func(running string)
	StartWait, DrainWait time.Duration
}

An Ensurer is unsupported here.

func (*Ensurer) Ensure

func (*Ensurer) Ensure(context.Context) (Info, error)

Ensure refuses: drive runs in the foreground on this platform.

type Exit

type Exit struct {
	Code   int
	Reason string
	Drive  int
}

An Exit is how a drive's process ended: its code, why it drained, and its record number, 0 when it never opened one.

func ReadExit

func ReadExit(log string) (Exit, bool)

ReadExit is how a drive's log ended, false while it runs.

type Info added in v0.62.0

type Info struct {
	Version  string
	API      int
	PID      int
	Started  time.Time
	Stopping bool
	Legacy   bool
}

Info is what Hello answers: which daemon runs, and whether it is stopping. Legacy is a daemon of a release before the Connect API, reached through its JSON protocol only to replace it.

func Hello added in v0.62.0

func Hello(ctx context.Context, dir, version string) (Info, error)

Hello asks the daemon in dir who it is. A daemon serving another API version answers, and APIError says so; one that speaks only the old JSON protocol answers through it, marked Legacy.

type RemoteListener added in v0.62.0

type RemoteListener interface {
	// Addr is the address to bind and whether the user's setting is on;
	// with no address, the third value says why none is wanted or possible.
	Addr() (addr string, on bool, why string)
	Listen(ln net.Listener) net.Listener
	Handler(h http.Handler) http.Handler
}

A RemoteListener is the daemon's listener on the tailnet: the address to bind, the peers it accepts and the check in front of the API. The daemon command builds it, so this package knows nothing of tokens.

type RemoteState added in v0.62.0

type RemoteState struct {
	Enabled     bool
	Addr        string // bound; "" when none is
	Reason      string // why none is bound
	URL         string // the web client's address while bound
	HTTPS       bool
	HTTPSReason string // why the listener serves plain HTTP
}

RemoteState is the tailnet listener as the daemon last reconciled it.

type RemoteTLS added in v0.62.0

type RemoteTLS interface {
	// TLS is the config to serve with and the host name its certificate
	// names; a nil config comes with why there is none, and the listener
	// serves plain HTTP meanwhile.
	TLS() (cfg *tls.Config, host string, why string)
}

A RemoteTLS listener serves HTTPS once it holds a certificate, because a browser installs a web app and shows notifications only over HTTPS.

type Run

type Run struct {
	Root  string    `json:"root"`
	Dir   string    `json:"dir"`
	Drive int       `json:"drive,omitempty"` // 0 until the drive printed its number
	PID   int       `json:"pid"`
	Since time.Time `json:"since"`
	Log   string    `json:"log"`
}

A Run is one drive process the daemon supervises.

type Server

type Server struct {
	Dir, Version          string
	Child                 func(argv []string) (string, []string)
	Idle, DrainWait, Tick time.Duration
	Log                   *log.Logger
	Handler               func(s *Server) http.Handler
	Key                   func(argv []string) string
	Remote                RemoteListener
	Service               bool
}

A Server is unsupported here.

func (*Server) Remember added in v0.62.0

func (*Server) Remember([]string)

func (*Server) ResumeDrive added in v0.62.0

func (*Server) ResumeDrive(string, string, []string, int) (Started, error)

func (*Server) RunDrive added in v0.62.0

func (*Server) RunDrive(DriveSpec) (Started, error)

func (*Server) Serve

func (*Server) Serve(context.Context) error

Serve refuses: there is no daemon on this platform.

func (*Server) SessionEnv added in v0.62.0

func (*Server) SessionEnv() []string

func (*Server) Status added in v0.62.0

func (*Server) Status() Status

Status, WatchProject, RunDrive, ResumeDrive, SessionEnv and Remember have nothing to report or run on this platform.

func (*Server) WatchProject added in v0.62.0

func (*Server) WatchProject(string, string, []string) (string, error)

type Started added in v0.62.0

type Started struct {
	Log    string
	Attach bool
	Drive  int
}

Started is a drive the daemon runs: its log, and whether the call joined one already running.

func RunDrive added in v0.62.0

func RunDrive(ctx context.Context, dir string, c DriveCall) (Started, error)

RunDrive asks the daemon in dir to run the drive, or to attach to it.

type Status added in v0.62.0

type Status struct {
	Info

	Runs    []Run
	Watches []Watch
	Remote  RemoteState
}

Status is what the daemon runs and watches, with who it is.

func GetStatus added in v0.62.0

func GetStatus(ctx context.Context, dir, version string) (Status, error)

GetStatus is who the daemon in dir is, and what it runs and watches.

type Watch

type Watch struct {
	Root string    `json:"root"`
	Dir  string    `json:"dir"`           // the main checkout
	Last time.Time `json:"last,omitzero"` // when the last pass ended
	Exit int       `json:"exit"`          // its exit code
	Log  string    `json:"log"`           // the project's pass log
}

A Watch is one project the daemon watches for tasks no drive owns: a `watch --pass` in its main checkout every few minutes.

Jump to

Keyboard shortcuts

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