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 ¶
const ( ReasonUpgrade = "upgrade" // the next daemon resumes it ReasonStopped = "stopped" // f10 daemon stop: it waits for its next run )
Why a drive exited ExitDrained.
const ( OpHello = "hello" OpRun = "run" OpStatus = "status" OpStop = "stop" OpWatch = "watch" )
Ops a Request names.
const ExitDrained = 6
ExitDrained is a drive's exit when it stopped for an upgrade, to be resumed by the next daemon; drive.go's exitDrained.
const ExitNothingWatched = 7
ExitNothingWatched is a pass's exit when the project has no task left to watch: the daemon stops watching it.
const NumberFileEnv = "F10_DRIVE_FILE"
NumberFileEnv names the file a drive the daemon runs writes its record number to, once the record is open.
const Supported = true
Supported reports whether this platform runs a daemon; elsewhere drive runs in the foreground.
Variables ¶
var ErrNotRunning = errors.New("no f10 daemon is running")
ErrNotRunning is a socket nobody listens on.
var ErrRunning = errors.New("an f10 daemon is already running")
ErrRunning is a second daemon finding the first one's lease held.
Functions ¶
func Newer ¶
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`.
Types ¶
type Ensurer ¶
type Ensurer struct {
Dir string
Version string
// Follow takes any daemon running, whatever its version: a client
// following a drive into the daemon that resumed it.
Follow bool
// Spawn starts a daemon detached; by default `<exe> daemon` in its own
// session, its output to the daemon log.
Spawn func(ctx context.Context) error
// Draining is told when an older daemon is being replaced, Kept when a
// daemon this client does not replace runs another version.
Draining, Kept func(running string)
// StartWait bounds how long a new daemon has to listen; DrainWait how
// long an old one has to drain.
StartWait, DrainWait time.Duration
}
An Ensurer finds this user's daemon, or starts one.
type Exit ¶
An Exit is how a drive's process ended: its code, why it drained, and its record number, 0 when it never opened one.
type Reply ¶
type Reply struct {
Error string `json:"error,omitempty"`
Stopping bool `json:"stopping,omitempty"` // a stop is draining it
Version string `json:"version,omitempty"`
PID int `json:"pid,omitempty"`
Started time.Time `json:"started,omitzero"`
Log string `json:"log,omitempty"` // run: the drive's log; watch: the project's pass log
Attach bool `json:"attach,omitempty"` // run: the log is a drive already running
Runs []Run `json:"runs,omitempty"` // status
Watches []Watch `json:"watches,omitempty"` // status
}
A Reply answers one Request; Error set means it was refused.
type Request ¶
type Request struct {
Op string `json:"op"`
Version string `json:"version,omitempty"` // hello: the client's
Argv []string `json:"argv,omitempty"` // run: drive's arguments, --foreground added by the daemon
Dir string `json:"dir,omitempty"` // run: where the drive was typed; watch: the main checkout
Root string `json:"root,omitempty"` // run, watch: the storage root, telling projects apart
Env []string `json:"env,omitempty"` // run, watch: the allowlisted environment
Key string `json:"key,omitempty"` // run: the record's command line, joined; "" never attaches
Resume int `json:"resume,omitempty"` // run: the record --resume names
Drain bool `json:"drain,omitempty"` // stop: let each drive reach a tick boundary
Upgrade bool `json:"upgrade,omitempty"` // stop: a newer daemon follows and resumes the drained drives
}
A Request is one call: an op and what it needs.
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 string // the run dir
Version string
// Child is the command a drive's argv runs as: by default the daemon's
// own binary, `drive --foreground <argv>`.
Child func(argv []string) (string, []string)
// Pass is the command one watch pass runs as in a project's main
// checkout: by default the daemon's own binary, `watch --pass`.
Pass func(dir string) (string, []string)
WatchEvery time.Duration // how often each watched project gets a pass
Idle time.Duration // no drive, no watched project and no call this long: exit
DrainWait time.Duration // how long a drain waits for drives before SIGTERM
Tick time.Duration // how often idleness is checked
Log *log.Logger
// contains filtered or unexported fields
}
A Server supervises drive processes for one user.
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.