daemon

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package daemon runs drives for one user, outside any session: `f10 drive` starts the daemon when none listens, hands it the command line, and tails the drive's log. Each drive is its own child process, `f10 drive --foreground`, run in the client's directory with the client's 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
)

Why a drive exited ExitDrained.

View Source
const (
	OpHello  = "hello"
	OpRun    = "run"
	OpStatus = "status"
	OpStop   = "stop"
	OpWatch  = "watch"
)

Ops a Request names.

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 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 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.

Functions

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 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 SocketPath

func SocketPath(dir string) string

SocketPath is where the daemon listens.

Types

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) (Reply, 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 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, logs: 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.

func Call

func Call(ctx context.Context, dir string, req Request, wait time.Duration) (Reply, error)

Call sends req to the daemon in dir and reads its reply.

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, Version          string
	Child                 func(argv []string) (string, []string)
	Idle, DrainWait, Tick time.Duration
	Log                   *log.Logger
}

A Server is unsupported here.

func (*Server) Serve

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

Serve refuses: there is no daemon on this platform.

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