Documentation
¶
Overview ¶
Package config resolves the bootstrap settings of `bubbles serve` from flags and BUBBLES_* environment variables, prepares the data directory and enforces single-instance and bind policy. Everything else the server needs lives in the settings table, not here.
Index ¶
Constants ¶
const ( DefaultHTTPSAddr = ":28225" DefaultHTTPAddr = ":28226" DefaultMDNSName = "bubbles" )
Default listen addresses and mDNS host name.
const ( DirFiles = "files" DirTmp = "tmp" DirTLS = "tls" DirLogs = "logs" DirBackups = "backups" )
Subdirectories of the data directory that EnsureDataDir creates.
const ( DirMode os.FileMode = 0o700 FileMode os.FileMode = 0o600 )
Permissions for data directory contents on Unix. On Windows the protected DACL set by EnsureDataDir plays this role.
const LockFileName = "bubbles.lock"
LockFileName is the single-instance lock inside the data directory.
Variables ¶
var ErrLocked = errors.New("data directory is locked by a running bubbles server")
ErrLocked means another process already holds the data directory. The CLI maps it to exit code 3. Test with errors.Is.
var ErrNoPrivateAddress = errors.New("no private LAN address found on this host: bubbles serves private networks only; " +
"connect to a LAN or pass --allow-public (BUBBLES_ALLOW_PUBLIC=1) to start anyway")
ErrNoPrivateAddress is returned by Config.CheckBindPolicy when the host has no private LAN address and --allow-public was not given.
Functions ¶
func EnsureDataDir ¶
EnsureDataDir creates dir and its subdirectories (files, tmp, tls, logs, backups) readable by the owner only: mode 0700 on Unix, a protected DACL granting SYSTEM, Administrators and the current user on Windows. It is safe to call repeatedly.
func EnvName ¶
EnvName returns the environment variable that mirrors a flag, for example "data-dir" becomes BUBBLES_DATA_DIR.
func WriteUsage ¶
WriteUsage prints the serve flags, their defaults and environment names.
Types ¶
type Config ¶
type Config struct {
DataDir string `json:"data_dir"`
HTTPSAddr string `json:"https_addr"`
HTTPAddr string `json:"http_addr"`
MDNSName string `json:"mdns_name"`
NoMDNS bool `json:"no_mdns"`
TLSCert string `json:"tls_cert"`
TLSKey string `json:"tls_key"`
TLSExtraDNS []string `json:"tls_extra_dns"`
// TailscaleCert serves the HTTPS certificate Tailscale issues for this
// machine's MagicDNS name to connections for that name.
TailscaleCert bool `json:"tailscale_cert"`
AllowPublic bool `json:"allow_public"`
PrintConfig bool `json:"print_config"`
}
Config holds the resolved `bubbles serve` settings.
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock holds the exclusive single-instance lock on a data directory. The operating system drops it if the process dies, so a crash never leaves a stale lock behind.
func AcquireLock ¶
AcquireLock takes the exclusive lock on <dataDir>/bubbles.lock, creating the file (mode 0600) if needed. It does not block: if another holder exists it returns an error wrapping ErrLocked. The data directory must exist.
type Options ¶
type Options struct {
// Getenv looks up environment variables; nil means os.Getenv.
Getenv func(string) string
// AsService selects the machine-wide default data directory used when the
// server runs as an OS service.
AsService bool
}
Options are the inputs to Parse besides the arguments.