webdetach

package
v0.1.31 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 13 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 webdetach keeps track of a detached `rotari web`: at most one per user and host, found through a record and a lease under the master directory, with its output in a log bounded by rotation. It knows nothing of HTTP or of how the server is started.

Index

Constants

View Source
const MaxLogBytes = 1 << 20

MaxLogBytes is about how large the log grows before it is rotated, as the Web event log is. One rotated generation is kept beside it.

Variables

View Source
var ErrRunning = errors.New("a detached rotari web is already running on this host")

ErrRunning says a detached server already holds this host's lease.

View Source
var ErrStarting = errors.New("a detached rotari web on this host is starting and has not recorded its address yet; try again in a moment")

ErrStarting says a detached server holds the lease but has not recorded its address yet.

Functions

func Ended

func Ended(paths Paths, pid int) (ended, clean bool, err error)

Ended says whether the detached server with pid is no longer running, and for one that is not, whether it stopped cleanly, removing its record, or went without, as when killed. A record of another server counts as this one having ended cleanly, since that server could not have started before this one released the lease. A held lease without a record is a server stopping or starting, so not yet an answer. A server that stops cleanly between the look at its record and the probe of its lease is reported as gone without cleaning up.

func KeepLogBounded

func KeepLogBounded(paths Paths, output *os.File) error

KeepLogBounded rotates the log a running server writes through output, which it cannot reopen: past MaxLogBytes it copies the log to the rotated file and truncates it in place. Lines written between the copy and the truncation are lost.

func OpenLog

func OpenLog(paths Paths, dirMode os.FileMode) (*os.File, int64, error)

OpenLog opens the log for a server about to start, first rotating one that has reached MaxLogBytes, and returns it with its size, from which the new server's output starts.

func ReadLogFrom

func ReadLogFrom(paths Paths, offset, limit int64) (string, error)

ReadLogFrom returns up to limit bytes of the log's end from offset on, as the reason a server that failed to start gives.

func TokenDigest

func TokenDigest(token string) string

TokenDigest is how a record names a token.

Types

type Holder

type Holder struct {
	// contains filtered or unexported fields
}

Holder is a detached server's hold on its host's lease.

func Hold

func Hold(paths Paths, dirMode os.FileMode) (*Holder, error)

Hold takes the host's lease for this process, or returns ErrRunning while another server holds it.

func (*Holder) Close

func (holder *Holder) Close() error

Close removes the record and releases the lease.

func (*Holder) Publish

func (holder *Holder) Publish(record Record) error

Publish writes record, readable only by its owner, replacing it whole.

type LogTail

type LogTail struct {
	// contains filtered or unexported fields
}

LogTail follows the log of a running server from where it was opened, starting over when the server truncates it in place (KeepLogBounded) or a new log replaces it.

func TailLog

func TailLog(paths Paths) (*LogTail, error)

TailLog starts following the log at its current end. A log that does not exist yet is followed from its start once it appears.

func (*LogTail) CopyTo

func (tail *LogTail) CopyTo(w io.Writer) error

CopyTo writes what the log gained since the last call to w.

type Paths

type Paths struct {
	Host, Dir, Record, Lease, Log, RotatedLog string
}

Paths are the files of a host's detached server under a master directory.

func PathsFor

func PathsFor(masterDir, host string) (Paths, error)

PathsFor returns the files of host's detached server under masterDir. The host name becomes part of file names, so it may not hold a separator.

type Record

type Record struct {
	Host       string    `json:"host"`
	PID        int       `json:"pid"`
	URL        string    `json:"url"`
	StartedAt  time.Time `json:"started_at"`
	Version    string    `json:"version"`
	Executable string    `json:"executable,omitempty"`
	Settings   Settings  `json:"settings"`
	// Binary is the rotari the server runs, to say when it is another one; nil in a
	// record an older rotari wrote.
	Binary *model.RunBinary `json:"binary,omitempty"`
}

Record is what a detached server says of itself. It never holds the token.

func Find

func Find(paths Paths) (Record, bool, error)

Find returns the detached server of paths when one is running. A record left by a server that is gone is removed, under the shared lock so no new server can record itself meanwhile. A lease that cannot be probed, or a running server's record that cannot be read, is an error, never "not running".

type Settings

type Settings struct {
	BaseDir                     string   `json:"basedir"`
	Host                        string   `json:"host"`
	Port                        int      `json:"port"`
	AllowControl                bool     `json:"allow_control"`
	Notifications               bool     `json:"notifications"`
	AllowExec                   bool     `json:"allow_exec"`
	AllowTerminal               bool     `json:"allow_terminal"`
	AllowedHosts                []string `json:"allowed_hosts"`
	ArtifactRoots               []string `json:"artifact_roots"`
	TerminalIdleTimeout         string   `json:"terminal_idle_timeout,omitempty"`
	TerminalMaxShells           int      `json:"terminal_max_shells,omitempty"`
	TerminalMaxShellsPerProject int      `json:"terminal_max_shells_per_project,omitempty"`
	TerminalReplaySize          int      `json:"terminal_replay_size,omitempty"`
	TerminalShell               string   `json:"terminal_shell,omitempty"`
	// TerminalNoShellIntegration is set when shell integration, on by default, is off, so
	// that a record without it means the default.
	TerminalNoShellIntegration bool `json:"terminal_no_shell_integration,omitempty"`
	// TokenSHA256 identifies the server's token without holding it.
	TokenSHA256 string `json:"token_sha256,omitempty"`
}

Settings are the options a detached server runs with, compared when one is asked for again. Port is the port it listens on.

func (Settings) Differences

func (s Settings) Differences(want Settings, portExplicit bool) []string

Differences names, as their flags, the settings in which want differs from s, a running server's. The port counts only when portExplicit; a token only when want names one, since a server started without one has generated its own; the terminal's settings only when both have the terminal on.

Jump to

Keyboard shortcuts

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