Documentation
¶
Overview ¶
Package supervisor runs dev servers in pseudo-terminals and tracks their lifecycle: start (with dependencies), readiness, graceful stop, crash handling with restart policies, resource usage and scrollback.
Index ¶
- Constants
- Variables
- func CompactSequences(s string) string
- func CursorUp(l string) int
- func IconPath(dir, explicit string) string
- func IsContainerRuntime(command string) bool
- func KeepOnExec(f *os.File, keep bool) (int, error)
- func KeepTerminalsOnExec(hs []Handoff, keep bool) error
- func LoginShellEnv() []string
- func NetworkWarning(e ports.Exposure, lan bool) bool
- func Notify(title, msg string)
- func PlainLine(l string) string
- func PlainLines(raw []byte, n int) []string
- func RedrawLine(l string, keep func(seq string) bool) string
- func SavedTemporaryPorts(stateDir string) func(port int) bool
- func ServerLookPath(name string, prepend []string) string
- func StripANSI(s string) string
- func Terminate(pgid int, done <-chan struct{}, grace time.Duration)
- type Display
- type Handoff
- type Health
- type Line
- type LogBuffer
- func (lb *LogBuffer) Clear()
- func (lb *LogBuffer) Close()
- func (lb *LogBuffer) Lines(n int) []string
- func (lb *LogBuffer) Locked(f func())
- func (lb *LogBuffer) Path() string
- func (lb *LogBuffer) Raw() []byte
- func (lb *LogBuffer) Subscribe() ([]byte, chan []byte)
- func (lb *LogBuffer) Tail(n, max int) []string
- func (lb *LogBuffer) TimedLines() []Line
- func (lb *LogBuffer) Unsubscribe(ch chan []byte)
- func (lb *LogBuffer) WatchLines(fn func(chunk []byte) bool)
- func (lb *LogBuffer) Write(p []byte) (int, error)
- type ShellRead
- type StartOptions
- type Status
- type Supervisor
- func (s *Supervisor) ActiveAddress(name string) (string, bool)
- func (s *Supervisor) ActivePort(name string) (int, bool)
- func (s *Supervisor) AddDesktopClient() func()
- func (s *Supervisor) Adopt(hs []Handoff) []string
- func (s *Supervisor) Apply(cfg *config.Config)
- func (s *Supervisor) ApplyRenamed(cfg *config.Config, old, name string)
- func (s *Supervisor) CancelHandoff()
- func (s *Supervisor) ClearLogs(name string)
- func (s *Supervisor) Config() *config.Config
- func (s *Supervisor) Definitions() []config.Server
- func (s *Supervisor) Dismiss(name string) error
- func (s *Supervisor) Environ() []string
- func (s *Supervisor) ForCheckout(name, dir string) (string, error)
- func (s *Supervisor) Input(name string, data []byte) error
- func (s *Supervisor) IsManagedPID(pid int) (string, bool)
- func (s *Supervisor) IsTemporary(name string) bool
- func (s *Supervisor) KillListener(l ports.Listener) error
- func (s *Supervisor) Killable(l ports.Listener) string
- func (s *Supervisor) Logs(name string) (*LogBuffer, bool)
- func (s *Supervisor) LookPath(name string) string
- func (s *Supervisor) Lookup(name string) (config.Server, bool)
- func (s *Supervisor) NotifyUser(title, message string)
- func (s *Supervisor) PrepareHandoff() ([]Handoff, error)
- func (s *Supervisor) Recover(restore bool)
- func (s *Supervisor) Resize(name string, cols, rows uint16)
- func (s *Supervisor) Restart(name string, opt StartOptions) error
- func (s *Supervisor) Run(ctx context.Context)
- func (s *Supervisor) SaveError() string
- func (s *Supervisor) SetForwarded(fn func(port int) (string, bool))
- func (s *Supervisor) SetPortRelease(fn func(port int))
- func (s *Supervisor) SetPublishedPorts(fn func(server string, port int) bool)
- func (s *Supervisor) SetTailnet(own ports.TailnetAddrs)
- func (s *Supervisor) Shutdown()
- func (s *Supervisor) Snapshot(daemonPort int) []View
- func (s *Supervisor) Start(name string, opt StartOptions) error
- func (s *Supervisor) Stop(name string) error
- func (s *Supervisor) Subscribe() chan struct{}
- func (s *Supervisor) TemporaryPorts() func(port int) bool
- func (s *Supervisor) Unsubscribe(ch chan struct{})
- func (s *Supervisor) WaitReady(ctx context.Context, name string, since time.Time, timeout time.Duration) error
- func (s *Supervisor) WantsPort(port int) bool
- func (s *Supervisor) WatchUsage() func()
- type View
Constants ¶
const ( // WatchInterval is how often a server's watched files are compared, at // most. A server whose scan takes longer waits watchShare times as long // as it took, times the number of servers scanned, so all scans // together use about 2% of a core, and a large tree slows only its // own server. WatchInterval = time.Second // WatchQuiet is how long changes must have stopped before a restart. WatchQuiet = time.Second // WatchFileLimit is how many files a server's patterns may match; files // past it, in walk order, are not watched. WatchFileLimit = 20000 )
const ExposureInterval = IdleSampleInterval
ExposureInterval is how often the listening addresses of running servers are read again; a server that becomes ready is read at once.
const IdleSampleInterval = 30 * time.Second
IdleSampleInterval is how often usage is sampled while no client shows it.
const PruneInterval = 10 * time.Second
PruneInterval is how often temporary servers are checked for a checkout that no longer exists.
const ReadyTimeout = 90 * time.Second
ReadyTimeout is how long ensure and restart wait for readiness when the caller gives no timeout.
const SampleInterval = 2 * time.Second
SampleInterval is how often usage is sampled while a client shows it, and how often ports are checked; histories hold historyLen samples at this spacing.
const ScheduleInterval = 15 * time.Second
ScheduleInterval is how often the wall clock is compared with the next scheduled runs. A short check instead of a timer per run, because timers follow the monotonic clock, which on macOS does not advance during sleep.
const TemporarySeparator = "--"
TemporarySeparator joins a configured server's name and a worktree label in a temporary server's name; it keeps the name a valid host label.
Variables ¶
var ANSIPattern = ansiRe
ANSIPattern is the pattern of one terminal escape sequence, for clients that clean raw terminal output themselves.
var ErrPortBusy = errors.New("port is in use by another process")
ErrPortBusy means the server's port is held by a process Portside did not start.
Functions ¶
func CompactSequences ¶ added in v0.12.0
CompactSequences shortens a run of kept escape sequences (colors and hyperlinks) that apply together before one character, so that output redrawing a line in color again and again cannot grow it without bound. A run of at most maxKept bytes is returned as it is. Longer runs keep the last hyperlink sequence and the colors from the last reset on, which leave the same style. A hyperlink longer than maxKept is dropped, and colors still longer than maxKept/2 keep only their last sequences, which can lose an earlier attribute of a program that sets hundreds without a reset.
func CursorUp ¶ added in v0.12.0
CursorUp returns how many rows a raw line moves the cursor up outside a cursor save and restore, at most maxCursorUp.
func IconPath ¶
IconPath returns the icon file for a server directory, preferring an explicitly configured one. Results are cached for a minute.
func IsContainerRuntime ¶
IsContainerRuntime reports whether a process name belongs to a container engine that publishes container ports on the host.
func KeepOnExec ¶
KeepOnExec keeps f open across exec, or lets exec close it again, and returns its descriptor number. Unlike f.Fd() it leaves the blocking mode alone: that mode belongs to the open file, which a listener or terminal still in use shares. Any process started while f is kept open inherits it, so callers hold syscall.ForkLock until the exec.
func KeepTerminalsOnExec ¶
KeepTerminalsOnExec keeps the terminals of hs open across exec and records their descriptor numbers, or (keep false) lets exec close them again. It takes no supervisor lock, so a caller holding syscall.ForkLock can use it.
func LoginShellEnv ¶
func LoginShellEnv() []string
LoginShellEnv reads the account's login-shell environment once, for commands outside the daemon (such as the app's helper, which starts with a minimal PATH). It returns nil when the shell cannot be read.
func NetworkWarning ¶ added in v0.4.0
NetworkWarning reports whether a listener with exposure e should be pointed out: it is reachable from the network and its server does not set `lan = true`. Tailnet-only and loopback listeners are not.
func Notify ¶
func Notify(title, msg string)
Notify shows a desktop notification. Text travels as arguments, never as script source, so server names cannot inject AppleScript.
func PlainLine ¶
PlainLine turns one raw line into readable text: escape sequences removed, the cursor rules of RedrawLine applied, and other control characters dropped.
func PlainLines ¶
PlainLines converts raw terminal output to readable lines.
func RedrawLine ¶ added in v0.12.0
RedrawLine returns the text one raw line leaves on its row of the screen, with the escape sequences keep accepts left in place and every other sequence and control character except tab removed. It follows bounded, line-local rules, not a terminal emulation:
- A carriage return, or a move to the first column (CSI G, CSI 0 G, CSI 1 G), starts the line over: a progress bar's last redraw wins and a shorter redraw leaves no tail. Trailing carriage returns are ignored, since a program's CRLF reaches the log as CR CR LF.
- Backspace and CSI n D move the cursor left, CSI n C right and CSI n G to column n; text written there overwrites what is under the cursor, as spinners redraw.
- CSI K and CSI 0 K erase to the end of the line, CSI 1 K to the cursor (with spaces) and CSI 2 K the whole line.
- Text between a cursor save (CSI s or ESC 7) and the following restore (CSI u or ESC 8) is dropped, together with the sequences inside: it was drawn elsewhere on the screen, as docker compose draws its key bar. A save without a restore on the same line changes nothing.
- Other cursor movement (up, down, absolute position) is ignored.
Columns count runes, so wide characters can misplace an overwrite. The line is untrusted program output, so the replay takes time linear in its length: numeric parameters saturate (csiParam), a cursor move pads at most maxRedrawColumn cells, only the first maxSaves cursor saves are replayed and the kept sequences in front of one character are compacted (CompactSequences).
func SavedTemporaryPorts ¶
SavedTemporaryPorts is TemporaryPorts for the temporary servers saved in stateDir, for use before a supervisor exists.
func ServerLookPath ¶
ServerLookPath finds name the way LookPath does for a process without a daemon (the CLI): the caller's PATH first, then prepend and the login shell's PATH, read only when needed. It returns "" when nothing matches.
Types ¶
type Display ¶ added in v0.12.0
type Display string
Display is the state a client shows for a server: its status, or one of the three states the status alone does not tell.
type Handoff ¶
type Handoff struct {
Name string `json:"name"`
PID int `json:"pid"`
PIDStart string `json:"pidStart"`
// PTY is the descriptor number of the terminal's controlling side.
PTY int `json:"pty"`
Config config.Server `json:"config"` // what the process was started with
Env []string `json:"env"`
Shell string `json:"shell"`
Tool string `json:"tool,omitempty"` // version manager the process runs under
Launch *launchInputs `json:"launch,omitempty"` // what Env was built from
Status Status `json:"status"`
Note string `json:"note,omitempty"`
Want bool `json:"want"`
Retries int `json:"retries"`
StartedAt time.Time `json:"startedAt"`
ReadyAt time.Time `json:"readyAt"`
ListenHost string `json:"listenHost,omitempty"`
ListenPorts []int `json:"listenPorts,omitempty"`
// LogReady says whether a line already matched the server's ready_log
// (nil from a daemon before it), and LogLine is the unfinished line the
// match continues with.
LogReady *bool `json:"logReady,omitempty"`
LogLine []byte `json:"logLine,omitempty"`
// MissingSince is when a running server stopped answering, so its lost
// readiness stays reported.
MissingSince time.Time `json:"missingSince,omitzero"`
Cols uint16 `json:"cols"`
Rows uint16 `json:"rows"`
// StartAfterExit says a start was asked for after the process ended,
// while its output still drained: the new daemon runs it.
StartAfterExit bool `json:"startAfterExit,omitempty"`
// contains filtered or unexported fields
}
Handoff describes a live server that a daemon passes to the binary it re-executes in its own process. The server keeps running: the process stays this daemon's child and its terminal's descriptor stays open across the exec, so the new daemon only has to take both over.
type Health ¶ added in v0.7.0
Health is whether a server should run and whether it is ready (running and still answering), the rule behind monitoring checks. A server should run when it crashed, when it exited although its restart policy is always (the policy gave up), and while it is wanted (started and not stopped by the user). A task is ready once done, and while its process runs unless required (a monitor naming it asks whether it is done), not while it waits for its dependencies; done, it is not expected to run, so it counts only when required, while it runs or is due to run again, and when it failed. Reason explains a server that should run and is not ready: its note, else its status.
type LogBuffer ¶
type LogBuffer struct {
// contains filtered or unexported fields
}
LogBuffer keeps a server's raw terminal output: a bounded in-memory tail for replay into terminals, an on-disk copy, and fan-out to live subscribers.
func NewMemoryLog ¶
func NewMemoryLog() *LogBuffer
NewMemoryLog returns a buffer that is kept only in memory.
func (*LogBuffer) Clear ¶
func (lb *LogBuffer) Clear()
Clear empties the scrollback (the on-disk log is kept).
func (*LogBuffer) Lines ¶
Lines returns the last n lines as plain text, with escape sequences removed and carriage-return redraws (progress bars) collapsed to their final state.
func (*LogBuffer) Locked ¶ added in v0.7.1
func (lb *LogBuffer) Locked(f func())
Locked runs f under the buffer's lock, as WatchLines functions run.
func (*LogBuffer) Path ¶ added in v0.6.0
Path is the on-disk log file, "" for a log kept only in memory.
func (*LogBuffer) Tail ¶
Tail returns the last n non-empty plain lines, each cut to max runes. It only looks at the end of the scrollback, so it is cheap enough to call on every state broadcast.
func (*LogBuffer) TimedLines ¶
TimedLines returns the scrollback as plain lines with their times.
func (*LogBuffer) Unsubscribe ¶
Unsubscribe stops delivery to ch.
func (*LogBuffer) WatchLines ¶ added in v0.7.1
WatchLines calls fn with every chunk written from now on, under the buffer's lock so that, unlike a subscription, it misses no output; it stops once fn returns true or another WatchLines (nil for none) replaces it.
type ShellRead ¶
type ShellRead struct {
Shell string // the account's login shell
Used string // the shell that was read: Shell, or bash or zsh in place of a non-POSIX one
Err string // why the read failed; servers then get the daemon's own environment
Path string // PATH from the read
}
ShellRead describes one read of the login-shell environment.
func ReadLoginShell ¶
ReadLoginShell reads the environment of the account's login shell. The environment is nil when the read fails.
type StartOptions ¶
type StartOptions struct {
// Takeover stops a foreign process holding the port before starting.
Takeover bool
// TakeoverPID, when set, limits Takeover to that process: a port held
// by another one (the confirmed process exited and something else took
// the port) leaves the server blocked, as without Takeover.
TakeoverPID int
// Since is when the start was asked for, now when zero. A task that a
// server depends on counts as done after a successful run that ended at
// or after it, so starts asked for together (a bulk start) share one run.
Since time.Time
// contains filtered or unexported fields
}
StartOptions tune Start.
type Status ¶
type Status string
Status is the lifecycle state of a server.
const ( Stopped Status = "stopped" // not running Starting Status = "starting" // process alive, not yet accepting connections Running Status = "running" // process alive and ready Stopping Status = "stopping" // stop requested, waiting for exit Crashed Status = "crashed" // exited with an error Exited Status = "exited" // exited cleanly on its own Blocked Status = "blocked" // could not start: port taken by another process )
type Supervisor ¶
type Supervisor struct {
// contains filtered or unexported fields
}
Supervisor owns all managed processes.
func New ¶
func New(cfg *config.Config, stateDir string) *Supervisor
New creates a supervisor for cfg. Logs and state go below stateDir.
func (*Supervisor) ActiveAddress ¶
func (s *Supervisor) ActiveAddress(name string) (string, bool)
ActiveAddress is the loopback endpoint used for health, links and proxying.
func (*Supervisor) ActivePort ¶
func (s *Supervisor) ActivePort(name string) (int, bool)
ActivePort is the port a server's live process uses, which can differ from the configured one until a restart applies an edit.
func (*Supervisor) AddDesktopClient ¶
func (s *Supervisor) AddDesktopClient() func()
AddDesktopClient registers a client that notifies the user itself and returns a function that unregisters it.
func (*Supervisor) Adopt ¶
func (s *Supervisor) Adopt(hs []Handoff) []string
Adopt takes over servers handed off by the daemon this process replaced. Call it before Recover, which saves the state and stops adopted servers that are no longer configured. A server whose process is gone or whose terminal descriptor is not usable is skipped; Recover then ends its process group and restores it as after a crash. It returns the names it adopted.
func (*Supervisor) Apply ¶
func (s *Supervisor) Apply(cfg *config.Config)
Apply swaps in a new configuration. Running servers keep running; if their definition changed they are flagged as stale until restarted. Servers that disappeared from the file are stopped.
func (*Supervisor) ApplyRenamed ¶
func (s *Supervisor) ApplyRenamed(cfg *config.Config, old, name string)
ApplyRenamed preserves a live process and its logs when an edit renames it.
func (*Supervisor) CancelHandoff ¶
func (s *Supervisor) CancelHandoff()
CancelHandoff resumes normal operation after a failed exec.
func (*Supervisor) ClearLogs ¶
func (s *Supervisor) ClearLogs(name string)
ClearLogs empties a server's scrollback.
func (*Supervisor) Config ¶
func (s *Supervisor) Config() *config.Config
Config returns the configuration currently applied.
func (*Supervisor) Definitions ¶
func (s *Supervisor) Definitions() []config.Server
Definitions returns the definitions of configured and temporary servers, each temporary server after its origin.
func (*Supervisor) Dismiss ¶
func (s *Supervisor) Dismiss(name string) error
Dismiss stops a server on request. A temporary server is removed as well, with its log files.
func (*Supervisor) Environ ¶
func (s *Supervisor) Environ() []string
Environ is the login-shell environment with the configured path entries, for helper commands the daemon runs on the user's behalf.
func (*Supervisor) ForCheckout ¶
func (s *Supervisor) ForCheckout(name, dir string) (string, error)
ForCheckout returns the server that runs name in the checkout containing dir: name itself for its own checkout, otherwise a temporary copy, created on first use with a free port. dir must be a checkout of the repository name runs from.
func (*Supervisor) Input ¶
func (s *Supervisor) Input(name string, data []byte) error
Input writes keystrokes to a server's terminal.
func (*Supervisor) IsManagedPID ¶
func (s *Supervisor) IsManagedPID(pid int) (string, bool)
IsManagedPID reports whether pid belongs to a process tree Portside runs.
func (*Supervisor) IsTemporary ¶
func (s *Supervisor) IsTemporary(name string) bool
IsTemporary reports whether name is a temporary server.
func (*Supervisor) KillListener ¶
func (s *Supervisor) KillListener(l ports.Listener) error
KillListener ends a foreign process that holds a port.
func (*Supervisor) Killable ¶
func (s *Supervisor) Killable(l ports.Listener) string
Killable reports why a foreign listener may not be killed, or "" if it may.
func (*Supervisor) Logs ¶
func (s *Supervisor) Logs(name string) (*LogBuffer, bool)
Logs returns the server's log buffer.
func (*Supervisor) LookPath ¶
func (s *Supervisor) LookPath(name string) string
LookPath finds an executable on the user's login-shell PATH plus the configured path entries. It returns "" when nothing matches.
func (*Supervisor) Lookup ¶
func (s *Supervisor) Lookup(name string) (config.Server, bool)
Lookup returns the definition of any server the supervisor knows, configured or temporary.
func (*Supervisor) NotifyUser ¶ added in v0.4.0
func (s *Supervisor) NotifyUser(title, message string)
NotifyUser shows a desktop notification other than a crash (a container problem, a device pairing or connecting) under the same notify setting and desktop-client guard as crashes: while the app is connected it notifies from the state itself.
func (*Supervisor) PrepareHandoff ¶
func (s *Supervisor) PrepareHandoff() ([]Handoff, error)
PrepareHandoff refuses new launches and returns every live server. A server that is being stopped blocks the handoff, since its stop must finish in one place. KeepTerminalsOnExec then keeps the terminals open across exec; CancelHandoff resumes launches when the exec fails.
func (*Supervisor) Recover ¶
func (s *Supervisor) Recover(restore bool)
Recover ends process groups orphaned by a daemon that died without cleaning up, then starts the servers that were running before (if the config asks for it and restore is set). Servers taken over by Adopt are left running. Call once, before serving requests.
func (*Supervisor) Resize ¶
func (s *Supervisor) Resize(name string, cols, rows uint16)
Resize changes a server's terminal size; new processes inherit it too.
func (*Supervisor) Restart ¶
func (s *Supervisor) Restart(name string, opt StartOptions) error
Restart stops a server (if running) and starts it again.
func (*Supervisor) Run ¶
func (s *Supervisor) Run(ctx context.Context)
Run performs periodic bookkeeping until ctx ends: resource sampling, listening checks, detection of foreign processes on configured ports and scheduled runs and watched files.
func (*Supervisor) SaveError ¶ added in v0.8.0
func (s *Supervisor) SaveError() string
SaveError reports why the server state could not be saved, or "" when the last write worked.
func (*Supervisor) SetForwarded ¶
func (s *Supervisor) SetForwarded(fn func(port int) (string, bool))
SetForwarded registers fn, which reports a port forwarded to another computer. Such a port is not probed for a stopped server (a connection would reach the other computer) and is shown as forwarded instead.
func (*Supervisor) SetPortRelease ¶
func (s *Supervisor) SetPortRelease(fn func(port int))
SetPortRelease registers fn, called with a server's port before it starts.
func (*Supervisor) SetPublishedPorts ¶
func (s *Supervisor) SetPublishedPorts(fn func(server string, port int) bool)
SetPublishedPorts registers fn, which reports whether a running container of a server's compose project publishes a port.
func (*Supervisor) SetTailnet ¶ added in v0.4.2
func (s *Supervisor) SetTailnet(own ports.TailnetAddrs)
SetTailnet sets how checkExposure learns this machine's Tailscale addresses, so a listener on one of them counts as tailnet; without it such listeners count as reachable from the network.
func (*Supervisor) Shutdown ¶
func (s *Supervisor) Shutdown()
Shutdown stops every server. The set of servers the user wanted running is persisted first so that the next daemon start can restore it; once the servers have exited, the state is saved again without their process groups, whose ids an unrelated program may get before the next start.
func (*Supervisor) Snapshot ¶
func (s *Supervisor) Snapshot(daemonPort int) []View
Snapshot returns all servers in configuration order. daemonPort is used to build *.localhost alias URLs served by the daemon's proxy.
func (*Supervisor) Start ¶
func (s *Supervisor) Start(name string, opt StartOptions) error
Start launches a server and, first, every server it depends on. It returns once the launch has been initiated; readiness is reported through status.
func (*Supervisor) Stop ¶
func (s *Supervisor) Stop(name string) error
Stop ends a server gracefully: Ctrl-C to its process group, then SIGTERM, then SIGKILL. It returns when the process has exited.
func (*Supervisor) Subscribe ¶
func (s *Supervisor) Subscribe() chan struct{}
Subscribe returns a channel that receives a signal whenever state changes.
func (*Supervisor) TemporaryPorts ¶
func (s *Supervisor) TemporaryPorts() func(port int) bool
TemporaryPorts reports the ports temporary servers are assigned or run on, which automatic ports in the config must skip.
func (*Supervisor) Unsubscribe ¶
func (s *Supervisor) Unsubscribe(ch chan struct{})
Unsubscribe stops change signals to ch.
func (*Supervisor) WaitReady ¶
func (s *Supervisor) WaitReady(ctx context.Context, name string, since time.Time, timeout time.Duration) error
WaitReady waits until name is ready: a server running and answering, checked live also for one already marked running, or a task (oneshot) done in a run that ended at or after since (see taskStateLocked). A server or task that ended or could not start fails with a *waitFailure.
func (*Supervisor) WantsPort ¶
func (s *Supervisor) WantsPort(port int) bool
WantsPort reports whether a server here is starting or running on port. It takes no lock, so code holding its own lock while the supervisor calls into it (such as the port forwarding) can ask.
func (*Supervisor) WatchUsage ¶ added in v0.3.0
func (s *Supervisor) WatchUsage() func()
WatchUsage registers a client that shows resource usage now, such as an open dashboard, and returns a function that unregisters it. While any is registered usage is sampled every SampleInterval; the first one gets a sample at once.
type View ¶
type View struct {
Name string `json:"name"`
Group string `json:"group,omitempty"`
Dir string `json:"dir"`
DirDisplay string `json:"dirDisplay"`
Cmd string `json:"cmd"`
Port int `json:"port"`
PortAuto bool `json:"portAuto,omitempty"`
URL string `json:"url,omitempty"`
Alias string `json:"alias,omitempty"`
Status Status `json:"status"`
// Unready marks a running server whose port or health check has failed
// for listenerLossDelay; it is not restarted, and its note says why.
Unready bool `json:"unready,omitempty"`
// Oneshot marks a task, which runs to completion; it is never running,
// but starting while it runs. Done marks a task whose last run exited
// with code 0 (status exited).
Oneshot bool `json:"oneshot,omitempty"`
Done bool `json:"done,omitempty"`
// Schedule is the crontab expression that starts the server; NextRun
// is when it next does (absent while disabled), LastRun when the
// latest scheduled run began. Temporary copies have none.
Schedule string `json:"schedule,omitempty"`
NextRun *time.Time `json:"nextRun,omitempty"`
LastRun *time.Time `json:"lastRun,omitempty"`
// Watch holds the file patterns, relative to Dir, whose changes
// restart the server.
Watch []string `json:"watch,omitempty"`
Note string `json:"note,omitempty"`
PID int `json:"pid,omitempty"`
StartedAt *time.Time `json:"startedAt,omitempty"`
ReadyAt *time.Time `json:"readyAt,omitempty"`
ExitedAt *time.Time `json:"exitedAt,omitempty"`
ExitCode *int `json:"exitCode,omitempty"`
RestartPending bool `json:"restartPending"`
// Retrying marks a pending restart that retry_after scheduled after the
// automatic restarts gave up, so the crash is still reported.
Retrying bool `json:"retrying,omitempty"`
ListenPorts []int `json:"listenPorts,omitempty"`
Listening bool `json:"listening"`
External *ports.Listener `json:"external,omitempty"`
Stale bool `json:"stale,omitempty"`
Removed bool `json:"removed,omitempty"`
Enabled bool `json:"enabled"`
DependsOn []string `json:"dependsOn,omitempty"`
Restart string `json:"restart"`
Restarts int `json:"restarts,omitempty"`
CPU float64 `json:"cpu"`
Mem int64 `json:"mem"`
CPUHistory []float64 `json:"cpuHistory,omitempty"`
MemHistory []int64 `json:"memHistory,omitempty"`
HasIcon bool `json:"hasIcon"`
Tail []string `json:"tail"` // last few plain output lines
Wanted bool `json:"wanted"`
// Tool is the environment tool the live process runs under, such as
// direnv or mise ("custom" for a configured wrap).
Tool string `json:"tool,omitempty"`
// Temporary marks a copy of the configured server Origin that runs in
// the checkout at Worktree; it is not in the config file.
Temporary bool `json:"temporary,omitempty"`
Origin string `json:"origin,omitempty"`
Worktree string `json:"worktree,omitempty"`
// ForwardedFrom names the connected computer whose server answers on
// this stopped server's port, forwarded here.
ForwardedFrom string `json:"forwardedFrom,omitempty"`
// Exposure is where the running server's listeners can be reached from
// (loopback, tailnet or network); absent until read. NetworkWarning
// marks one reachable from the network whose config does not set
// `lan = true`, which LAN reports. Kind names the tool the command
// starts (see discover.CommandKind) while NetworkWarning is set, for the
// dashboard's fix.
Exposure ports.Exposure `json:"exposure,omitempty"`
NetworkWarning bool `json:"networkWarning,omitempty"`
LAN bool `json:"lan,omitempty"`
Kind string `json:"kind,omitempty"`
}
View is the public, JSON-serialisable state of one server.
func GroupTargets ¶ added in v0.12.0
GroupTargets returns the members of a group that a group action applies to, in their order: "start" takes the enabled members without a process, "stop" and "restart" the members CanStop reports for (the dashboard's groupTargets in web/src/features/servers/actions.ts). Other verbs take none.
func (View) CanStop ¶ added in v0.12.0
CanStop reports whether a stop has something to do: a process runs, or an automatic restart is due (the dashboard's canStop in web/src/features/servers/format.ts).
func (View) Display ¶ added in v0.12.0
Display is the state to show for the server, the rule the dashboard's displayStatus and the menu bar app's Server.displayStatus mirror.
func (View) HasProcess ¶ added in v0.12.0
HasProcess reports whether the server has a process: it runs, starts or stops (the dashboard's hasProcess in web/src/features/servers/format.ts).