Documentation
¶
Overview ¶
Package daemon runs drives for one user, outside any session. Each drive is its own `f10 start --foreground` child in the client's directory and environment, so leases and crash recovery stay the drive's own.
Index ¶
- Constants
- Variables
- func APIError(info Info, version string) error
- func DriveEnv(environ, extra []string) []string
- func EnvOf(name string) string
- func ExitPath(log string) string
- func FindLog(dir, root string, n int) string
- func IsLocal(req connect.AnyRequest) bool
- func LocalEnv(req connect.AnyRequest, env []string) []string
- func LogPath(dir string) string
- func Newer(a, b string) bool
- func RunDir() string
- func SocketHTTP(dir string) *http.Client
- func SocketPath(dir string) string
- func Stop(ctx context.Context, dir string, drain, upgrade bool) error
- func WatchProject(ctx context.Context, runDir, root, dir string, env []string) (string, error)
- func WithCaller(ctx context.Context, c Caller) context.Context
- type Caller
- type Client
- type DriveCall
- type DriveSpec
- type Ensurer
- type Exit
- type Info
- type RemoteListener
- type RemoteState
- type RemoteTLS
- type Run
- type Server
- func (s *Server) Info() Info
- func (s *Server) Remember(env []string)
- func (s *Server) ResumeDrive(root, dir string, env []string, n int) (Started, error)
- func (s *Server) RunDrive(spec DriveSpec) (Started, error)
- func (s *Server) Serve(ctx context.Context) error
- func (s *Server) SessionEnv() []string
- func (s *Server) Status() Status
- func (s *Server) Stop(drain, upgrade bool)
- func (s *Server) WatchProject(root, dir string, env []string) (string, error)
- type Started
- type Status
- type Watch
Constants ¶
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.
const ( OldNumberFileEnv = "F10_DRIVE_FILE" OldResumeEnv = "F10_DRIVE_RESUMES" )
OldNumberFileEnv and OldResumeEnv are the two names above as the last release spelt them. A daemon sets both spellings and its child reads either, because across an upgrade the two can be one release apart.
one-release alias: the F10_DRIVE_FILE and F10_DRIVE_RESUMES variables
const APIVersion = 1
APIVersion is the control-plane API version this binary serves and calls; it rises only when a v2 package lands.
const ExitDrained = 6
ExitDrained is a drive's exit when it stopped for an upgrade, to be resumed by the next daemon.
const ExitNothingWatched = 7
ExitNothingWatched is a pass's exit when the project has no task left to watch: the daemon stops watching it.
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.
const NumberFileEnv = "F10_BATCH_FILE"
NumberFileEnv names the file a batch the daemon runs writes its record number to, once the record is open.
const ResumeEnv = "F10_BATCH_RESUMES"
ResumeEnv is set on every batch a daemon runs that starts an ExitResume again. A batch under an older daemon, which lacks it, names the resume command instead of exiting for a restart that never comes.
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.
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.
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
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 EnvOf ¶ added in v0.71.0
EnvOf reads one of the two variables above under its new name, else its old 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 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`.
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
SocketHTTP is an HTTP client whose every request goes to the socket in dir.
func Stop ¶ added in v0.62.0
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
WatchProject hands the project at root, its main checkout dir, to the daemon's watch passes, and returns the pass log.
Types ¶
type Caller ¶ added in v0.62.0
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.
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.
type DriveCall ¶ added in v0.62.0
type DriveCall struct {
Args []string // the drive's arguments, as f10 start 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.
type DriveSpec ¶ added in v0.62.0
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 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.
func (*Ensurer) Ensure ¶
Ensure returns a daemon listening, starting one when none does. Only a strictly newer client replaces a running one, so two versions never take turns; the start lease keeps two clients at once to one daemon. A daemon kept whose API this client does not speak is an error naming both.
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 Info ¶ added in v0.62.0
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.
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 string // the run dir
Version string
// Child is the command a drive's argv runs as: by default the daemon's
// own binary, `start --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
// Handler is the API the socket serves, built over this server; the
// daemon command passes the Connect handlers, a test its own.
Handler func(s *Server) http.Handler
// Key is the attach key of a drive's arguments, "" for a drive that must
// start its own process (one given answers).
Key func(argv []string) string
// Remote is the tailnet listener, nil for the socket alone. While its
// setting is on the daemon never idles out.
Remote RemoteListener
// Service is a daemon launchd or systemd keeps: it never idles out, and
// while another daemon holds the lease it waits to take over.
Service bool
// contains filtered or unexported fields
}
A Server supervises drive processes for one user.
func (*Server) Remember ¶ added in v0.62.0
Remember keeps env as the newest local session, when it comes from inside one, as a watch or a drive call does.
func (*Server) ResumeDrive ¶ added in v0.62.0
ResumeDrive starts drive n again with --resume, as a stopped drive's answer does.
func (*Server) RunDrive ¶ added in v0.62.0
RunDrive attaches to the drive already running this record, else starts it, and returns its log.
func (*Server) Serve ¶
Serve holds the daemon's lease, listens, and supervises until it is idle, stopped, or ctx ends (a drain).
func (*Server) SessionEnv ¶ added in v0.62.0
SessionEnv is the newest local session's environment, nil before any client registered one.
type Started ¶ added in v0.62.0
Started is a drive the daemon runs: its log, and whether the call joined one already running.
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.
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.