Functions
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(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(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(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(token string) string
TokenDigest is how a record names a token.
Types
type Holder struct {
// Has unexported fields.
}
Holder is a detached server's hold on its host's lease.
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 *Holder) Close() error
Close removes the record and releases the lease.
func (holder *Holder) Publish(record Record) error
Publish writes record, readable only by its owner, replacing it whole.
type LogTail struct {
// Has 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(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 (tail *LogTail) CopyTo(w io.Writer) error
CopyTo writes what the log gained since the last call to w.
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(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 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(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 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 (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.