serverready

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package serverready reports whether a server can run the control plane and in which mode. Assess is pure over Facts, so each proxy and port situation is a table fixture; Collect gathers real Facts.

Index

Constants

View Source
const (
	StatusPass = "pass"
	StatusWarn = "warn"
	StatusFail = "fail"
	StatusInfo = "info"
)

Status of one check.

View Source
const (
	ModeOwnPorts    = "own_ports"
	ModeBehindProxy = "behind_proxy"
)

Install modes.

View Source
const (
	CheckOS            = "os"
	CheckDocker        = "docker"
	CheckDockerRootles = "docker_rootless"
	CheckDockerSocket  = "docker_socket"
	CheckPort80        = "port_80"
	CheckPort443       = "port_443"
	CheckDisk          = "disk"
	CheckMemory        = "memory"
	CheckFirewall      = "firewall"
	CheckDNS           = "dns"
)

Check IDs.

View Source
const (
	ProxyTraefik = "traefik"
	ProxyNginx   = "nginx"
	ProxyCaddy   = "caddy"
	ProxyApache  = "apache"
	ProxyHAProxy = "haproxy"
	ProxyOther   = "unknown"
)

Proxy kinds recognised by process or container image name.

Variables

This section is empty.

Functions

func ClassifyProxy

func ClassifyProxy(process, image string) string

ClassifyProxy names the proxy family of a process or image, "" if neither looks like a web server or proxy.

Types

type Check

type Check struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	Status string `json:"status"`
	Detail string `json:"detail"`
	Fix    string `json:"fix,omitempty"`
}

Check is one result.

type DockerInfo

type DockerInfo struct {
	Version  string
	Rootless bool
}

DockerInfo is what the engine says about itself.

type Facts

type Facts struct {
	OS      string `json:"os"`
	Arch    string `json:"arch"`
	Systemd bool   `json:"systemd"`

	Listeners []Listener `json:"listeners"`
	// SelfProcesses are process names that mean "this product is already
	// running here", so its own ports are not a conflict.
	SelfProcesses []string `json:"-"`

	DockerPresent  bool   `json:"docker_present"`
	DockerVersion  string `json:"docker_version,omitempty"`
	DockerRootless bool   `json:"docker_rootless"`
	DockerError    string `json:"docker_error,omitempty"`
	// DockerSocketWorldWritable and DockerTCPExposed flag an exposed daemon.
	DockerSocketPath          string `json:"docker_socket_path,omitempty"`
	DockerSocketWorldWritable bool   `json:"docker_socket_world_writable"`

	DiskFreeGB float64 `json:"disk_free_gb"`
	DiskPath   string  `json:"disk_path,omitempty"`
	MemoryMB   int     `json:"memory_mb"`

	Firewall Firewall `json:"firewall"`

	Domain    string   `json:"domain,omitempty"`
	DomainIPs []string `json:"domain_ips,omitempty"`
	DNSError  string   `json:"dns_error,omitempty"`
	LocalIPs  []string `json:"local_ips,omitempty"`
}

Facts is everything Assess needs, gathered once.

func Collect

func Collect(ctx context.Context, p Probes, req Request) Facts

Collect gathers Facts. A probe that fails leaves its field at the zero value and, for Docker, records the error: a readiness report must never itself fail because one tool is missing.

type Firewall

type Firewall struct {
	// Kind is ufw, firewalld or "" when none was found.
	Kind    string `json:"kind"`
	Active  bool   `json:"active"`
	Known   bool   `json:"known"`
	Allowed []int  `json:"allowed,omitempty"`
}

Firewall describes the host firewall as far as it can be read.

func ParseFirewalld

func ParseFirewalld(ports, services string) Firewall

ParseFirewalld reads firewall-cmd --list-ports and --list-services output.

func ParseUFW

func ParseUFW(out string) Firewall

ParseUFW reads `ufw status` output.

type Listener

type Listener struct {
	Addr    string `json:"addr"`
	Port    int    `json:"port"`
	Process string `json:"process,omitempty"`
	PID     int    `json:"pid,omitempty"`
	// Container and Image are set when a Docker container publishes the port.
	Container string `json:"container,omitempty"`
	Image     string `json:"image,omitempty"`
}

Listener is one TCP listening socket and who owns it.

func HostUDPHolder

func HostUDPHolder(ctx context.Context, port int) (Listener, bool)

HostUDPHolder names the local process bound to a UDP port, if ss can see it.

func ParseSS

func ParseSS(out string) []Listener

ParseSS reads `ss -H -ltnp` output into listeners. Lines it cannot read are skipped: a half-parsed table must not hide the ports that did parse.

func ParseSSUDP

func ParseSSUDP(out string) []Listener

ParseSSUDP reads `ss -H -lunp` output into bound UDP sockets.

type Probes

type Probes struct {
	SS            func(ctx context.Context) (string, error)
	UFW           func(ctx context.Context) (string, error)
	Firewalld     func(ctx context.Context) (ports, services string, err error)
	DockerInfo    func(ctx context.Context) (DockerInfo, error)
	Published     func(ctx context.Context) ([]Listener, error)
	SocketMode    func(path string) (os.FileMode, error)
	DiskFreeGB    func(path string) (float64, error)
	MemoryMB      func() (int, error)
	LookupHost    func(ctx context.Context, host string) ([]string, error)
	LocalIPs      func() []string
	HasSystemd    func() bool
	DockerPresent func() bool
}

Probes are the host reads Collect performs, injected so tests need no host.

func HostProbes

func HostProbes() Probes

HostProbes returns the real probes. DockerInfo and Published are left nil for the caller, which already holds an engine client.

type Report

type Report struct {
	Checks []Check `json:"checks"`
	// Mode is the recommended install mode.
	Mode string `json:"mode"`
	// Proxy is the reverse proxy found on 80/443, "" when none.
	Proxy string `json:"proxy,omitempty"`
	// Holders names who owns each contested port.
	Holders map[int]string `json:"holders,omitempty"`
	// NextStep is the exact command or action to take now.
	NextStep string `json:"next_step"`
	Blocked  bool   `json:"blocked"`
	Summary  string `json:"summary"`
}

Report is the assessment.

func Assess

func Assess(f Facts, th Thresholds) Report

Assess turns facts into a report and a recommended mode.

type Request

type Request struct {
	Domain        string
	DataDir       string
	SelfProcesses []string
	SocketPath    string
}

Request is what to look at.

type Thresholds

type Thresholds struct {
	MinDiskGB       float64
	MinMemoryMB     int
	MinDockerMajor  int
	HTTPPort        int
	HTTPSPort       int
	InstallerPrefix string
}

Thresholds are the minimums, supplied by the caller from configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL