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
- Variables
- func Ended(paths Paths, pid int) (ended, clean bool, err error)
- func KeepLogBounded(paths Paths, output *os.File) error
- func OpenLog(paths Paths, dirMode os.FileMode) (*os.File, int64, error)
- func ReadLogFrom(paths Paths, offset, limit int64) (string, error)
- func TokenDigest(token string) string
- type Holder
- type LogTail
- type Paths
- type Record
- type Settings
Constants ¶
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 ¶
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.
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 ¶
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 ¶
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 ¶
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 ¶
ReadLogFrom returns up to limit bytes of the log's end from offset on, as the reason a server that failed to start gives.
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 ¶
Hold takes the host's lease for this process, or returns ErrRunning while another server holds it.
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.
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.
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 ¶
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 ¶
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.