Documentation
¶
Overview ¶
Package bg runs long-lived client-side commands (port forwards, FUSE mounts, clipboard sync) in the background and keeps a registry of them so `remohop ps` and `remohop stop` can find them again.
A command that supports -b/--background does:
if background && !bg.InChild() {
msg, pid, err := bg.Start(30 * time.Second)
// print msg, return
}
... establish the forward / mount ...
done := bg.Ready(bg.Info{Kind: "forward", Target: env.Target, Detail: "..."}, "forwarding ...")
defer done()
<-ctx.Done()
Start re-executes the current binary with identical arguments, detached from the terminal, and blocks until that child calls Ready (or dies). Ready also works in the foreground, where it only records the process.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("no such background process")
ErrNotFound is returned by Stop for a PID that is not a recorded process.
Functions ¶
func InChild ¶
func InChild() bool
InChild reports whether this process is the detached child of Start.
func Ready ¶
Ready records this process in the registry and, when running as the child of Start, releases the waiting parent with msg. The returned function removes the record; defer it.
Types ¶
type Info ¶
type Info struct {
Kind string `json:"kind"` // "forward", "mount", "clip", ...
Target string `json:"target"` // remote peer
Detail string `json:"detail"` // human-readable, e.g. "127.0.0.1:18080 -> 8080"
PID int `json:"pid"`
Started time.Time `json:"started"`
Log string `json:"log,omitempty"`
}
Info describes one running background (or foreground long-lived) command.