Documentation
¶
Overview ¶
Package daemon is the long-lived `tb` background process. It keeps one connection per device open so agent commands (`tb look`, `tb do`) cost a few milliseconds instead of a device handshake each. The CLI starts it on demand and talks to it over a unix socket.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotRunning = errors.New("tb daemon is not running")
ErrNotRunning is StopDaemon's error when no daemon answers.
Functions ¶
func BuildID ¶
func BuildID() string
BuildID identifies this binary as it was when the process started (its size and modification time), so a client can tell a daemon started from an older build.
func SocketPath ¶
func SocketPath() string
SocketPath is where the daemon listens. Unix socket paths are limited to ~104 bytes, so a long state directory gets its socket in the temp folder, named by a hash of the directory.
func StopAfterReply ¶ added in v0.5.3
StopAfterReply, called by a handler, stops the server once the handler's answer is written to its client (the stop command: its answer must reach the client before the socket goes).
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a connection to the daemon.
func Connect ¶
Connect connects to the daemon, starting it if it is not running, and replacing it if it runs an older build of tb.
type Handler ¶
Handler serves one request. send streams a partial response (for watch-like commands).
type Request ¶
type Request struct {
Cmd string `json:"cmd"`
Args json.RawMessage `json:"args,omitempty"`
Cwd string `json:"cwd,omitempty"`
}
Request is one CLI call. Args are command-specific.
type Response ¶
type Response struct {
OK bool `json:"ok"`
Exit int `json:"exit"`
Text string `json:"text,omitempty"`
JSON json.RawMessage `json:"json,omitempty"`
Image []byte `json:"image,omitempty"`
More bool `json:"more,omitempty"`
}
Response is the answer. Streaming commands send several with More=true, then a final one.
func StopDaemon ¶ added in v0.5.3
StopDaemon stops the running daemon (it does not start one) and returns its answer once the daemon has finished stopping: its commands cancelled and its sessions' devices closed and freed, so a tb started right after finds them free (issue #124).
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server accepts CLI connections on the unix socket.
func (*Server) OnStop ¶ added in v0.5.3
OnStop adds f to what the server runs when it stops (Stop, the idle exit, a signal from StopOnSignals), before Serve returns: after the requests still running were cancelled and have ended. f must return by ctx's deadline.
func (*Server) Serve ¶
Serve listens until Stop, or until idle with no client for the idle duration.
func (*Server) StopOnSignals ¶ added in v0.5.3
StopOnSignals stops the server, as Stop does, when the process gets one of sigs. After the first, the signals are the system's again (a second Ctrl-C ends the process at once). The returned func stops listening for them.