Documentation
¶
Overview ¶
Package config loads and edits the TOML file that lists managed servers.
Index ¶
- Constants
- Variables
- func AddServer(path string, s Spec) error
- func CacheGood(stateDir, path string, data []byte) error
- func CheckRevision(path, rev string) error
- func IsComposeCommand(cmd string) bool
- func IsDashboardLabel(label string) bool
- func NewDashboardLabel() string
- func Quote(s string) string
- func ReadPort(path string) (int, bool, error)
- func RemoveServer(path, name string) error
- func Render(s Spec) string
- func ReplaceIfUnchanged(path string, text []byte, rev string) error
- func Revision(data []byte) string
- func SetEnabled(path, name string, enabled bool) error
- func SetKey(path, name, k, literal string) error
- func SetTopLevel(path, k, literal string) error
- func SpecDir(root, abs string) string
- func StarterRoot() string
- func UpdateServer(path, name string, s Spec) error
- func ValidName(name string) error
- func WriteAtomic(path string, data []byte) error
- func WriteStarter(path string) error
- type Config
- type Duration
- type Server
- type Spec
Constants ¶
const ( RestartNo = "no" RestartOnFailure = "on-failure" RestartAlways = "always" // WrapAuto (the default) detects a server's tool environment and // WrapNone turns detection off. WrapAuto = "auto" WrapNone = "none" )
Restart policies.
const AutoPortBase = 3001
AutoPortBase is the first port handed out to servers without an explicit port. It is 3001 rather than 3000 because 3000 is the most contested default.
const ComposeStop = "30s"
ComposeStop is the stop timeout given to compose stacks found by discovery or imported, so containers can shut down cleanly.
Variables ¶
var ErrConflict = errors.New("the config file changed since it was loaded; reload and try again")
ErrConflict means the file changed since the caller read it.
var ErrNotFound = errors.New("config file not found")
ErrNotFound is returned when the configuration file does not exist.
var Reserved = map[int]bool{ 3659: true, 4045: true, 5000: true, 5060: true, 5061: true, 6000: true, 6566: true, 6665: true, 6666: true, 6667: true, 6668: true, 6669: true, 6697: true, 7000: true, 10080: true, }
Reserved ports are skipped by automatic assignment: 5000/7000 belong to the macOS AirPlay Receiver, the rest are on browsers' unsafe-port lists.
Functions ¶
func CheckRevision ¶
CheckRevision returns ErrConflict when the file no longer has revision rev, for an edit made from a form that showed that revision.
func IsComposeCommand ¶
IsComposeCommand reports whether a server's command runs a compose stack.
func IsDashboardLabel ¶
IsDashboardLabel reports whether label has the form of a dashboard host label.
func NewDashboardLabel ¶
func NewDashboardLabel() string
NewDashboardLabel returns a random label that IsDashboardLabel accepts.
func ReadPort ¶
ReadPort reads just the dashboard port even when server validation fails, and whether it is automatic (the file sets none), as Parse decides.
func RemoveServer ¶
RemoveServer deletes a server table and the comments directly above it.
func ReplaceIfUnchanged ¶
ReplaceIfUnchanged writes text only if the file still has revision rev.
func SetEnabled ¶
SetEnabled toggles a server without touching anything else in its table.
func SetKey ¶
SetKey sets one key inside a server table to a TOML literal, keeping every other line (and comment) of the table untouched.
func SetTopLevel ¶
SetTopLevel sets a top-level key (outside any table) to a TOML literal.
func SpecDir ¶
SpecDir is how the absolute directory abs is written as a server's dir: relative to root when inside it ("" for root itself), otherwise with the home directory shortened to ~.
func StarterRoot ¶
func StarterRoot() string
StarterRoot picks the directory most likely to hold the user's projects: the candidate with the most projects one or two levels down, the more conventional name winning a tie, else the home directory.
func UpdateServer ¶
UpdateServer patches changed fields of name with s (which may carry a new name). Comment lines directly above the table are kept unless s.Comment is set.
func ValidName ¶
ValidName reports whether name can be used as a server name. Names double as DNS labels for the <name>.localhost proxy, hence the strict alphabet.
func WriteAtomic ¶
WriteAtomic replaces the file at path (or its symlink target) under the lock.
func WriteStarter ¶
WriteStarter creates a commented configuration file with no servers.
Types ¶
type Config ¶
type Config struct {
Path string
Root string
Port int
// PortAuto is true when the file sets no dashboard port, so the daemon
// may choose another one when the default is taken (kept in the state
// directory, see daemon.SavedPort).
PortAuto bool
Shell string
PathPrepend []string
Env map[string]string
Restore bool
Notify bool
Editor string
Terminal string
StopTimeout time.Duration
// DockerStart is the command that starts the container engine; empty
// means the engine behind the active Docker context is detected.
DockerStart string
// Share lets the owner's other devices on Tailscale connect to this daemon.
Servers []Server
// Warnings are non-fatal problems such as duplicate ports.
Warnings []string
}
Config is the parsed configuration file.
func LoadAssignedPorts ¶
LoadAssignedPorts loads the daemon's config and persists automatic ports under the edit lock, so later removals or reordering cannot change them. Automatic ports skip the ports avoid reports (nil avoids none), such as those of temporary servers, which the config does not list.
func LoadRecoverable ¶
LoadRecoverable always returns usable settings. Its error describes the requested file, which remains editable while the last good settings run.
func (*Config) FreePort ¶
FreePort returns the lowest unused, unreserved port at or above AutoPortBase.
func (*Config) Resolve ¶
Resolve expands names and group names into server names, keeping config order.
type Duration ¶
Duration is a time.Duration written as a string such as "10s" in TOML.
func (*Duration) UnmarshalText ¶
type Server ¶
type Server struct {
Name string
Dir string // absolute
DirRaw string // as written in the file
Cmd string
Port int // 0 means the server does not listen on a port
PortAuto bool // port was assigned automatically
Group string
DependsOn []string
Projects []string
Env map[string]string
Restart string
Health string // optional HTTP path probed for readiness, e.g. "/"
Icon string // optional absolute icon path
Open string // optional path appended to the URL when opening
// Wrap selects how the command enters the project's tool environment:
// "" or WrapAuto detects direnv, devbox, mise or a Node version file, WrapNone runs
// it as is, anything else is a command prefix.
Wrap string
Stop time.Duration
StopRaw string // stop_timeout as written, "" when inherited
IconRaw string // icon as written
Enabled bool
// LAN says the server is meant to be reachable from other devices, so
// listening on the network is not pointed out.
LAN bool
// OnCrash is the shell command run once the server has crashed for good:
// the server's own on_crash, else the top-level one; "" runs nothing.
OnCrash string
// ReadyLog, when set, is a regular expression a line of the server's
// output must match before it counts as running (checked at load).
ReadyLog string
// ReadyAfter is how long the process must have run before it counts as
// running; 0 means the default (immediately with a port, 1.5 s without).
ReadyAfter time.Duration
}
Server is one managed dev server with defaults applied and paths resolved.
type Spec ¶
type Spec struct {
Name string `json:"name"`
Dir string `json:"dir"`
Cmd string `json:"cmd"`
Port *int `json:"port,omitempty"`
Group string `json:"group,omitempty"`
DependsOn []string `json:"dependsOn,omitempty"`
Projects []string `json:"projects,omitempty"`
Env map[string]string `json:"env,omitempty"`
Restart string `json:"restart,omitempty"`
Health string `json:"health,omitempty"`
Icon string `json:"icon,omitempty"`
Open string `json:"open,omitempty"`
Stop string `json:"stopTimeout,omitempty"`
Enabled *bool `json:"enabled,omitempty"`
// Comment is written as # lines above the table header.
Comment string `json:"comment,omitempty"`
}
Spec describes a server as written to the file. Empty fields are omitted.