daemon

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 17 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 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

View Source
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 Dir

func Dir() string

Dir is Test Buddy's state directory (~/.testbuddy).

func LogPath

func LogPath() string

func Running

func Running() bool

Running reports whether a daemon answers on the socket.

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

func StopAfterReply(ctx context.Context)

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

func Connect() (*Client, error)

Connect connects to the daemon, starting it if it is not running, and replacing it if it runs an older build of tb.

func (*Client) Call

func (c *Client) Call(req Request, onPart func(Response)) (Response, error)

Call sends a request and calls onPart for each streamed part; it returns the final response.

func (*Client) Close

func (c *Client) Close() error

type Handler

type Handler func(ctx context.Context, req Request, send func(Response)) Response

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

func StopDaemon() (Response, error)

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 NewServer

func NewServer(idle time.Duration) *Server

func (*Server) Handle

func (s *Server) Handle(cmd string, h Handler)

func (*Server) OnStop added in v0.5.3

func (s *Server) OnStop(f func(ctx context.Context))

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

func (s *Server) Serve() error

Serve listens until Stop, or until idle with no client for the idle duration.

func (*Server) Stop

func (s *Server) Stop()

Stop makes Serve return.

func (*Server) StopOnSignals added in v0.5.3

func (s *Server) StopOnSignals(sigs ...os.Signal) func()

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.

Jump to

Keyboard shortcuts

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