Documentation
¶
Overview ¶
Package server implements the Aviary HTTPS server.
Index ¶
- Variables
- func BearerMiddleware(token string, authDisabled func() bool, next http.Handler) http.Handler
- func GenerateToken() (string, error)
- func InstallService(opts ServiceOptions) error
- func IsRunning() (bool, int, error)
- func LoadOrGenerateTLS(t config.TLSConfig) (tls.Certificate, error)
- func LoadOrGenerateToken() (string, bool, error)
- func LoadToken() (string, error)
- func LoginHandler(token string, authDisabled func() bool) http.HandlerFunc
- func PIDPath() string
- func ReadPID() (int, error)
- func RemovePID() error
- func SelfSignedSANs(t config.TLSConfig) []string
- func SetStartupWatches(watches []projects.Watch)
- func StartService(name string) error
- func StopService(name string) error
- func TLSFiles(t config.TLSConfig, regenerate bool) (certFile, keyFile string, err error)
- func UninstallService(name string) error
- func WritePID() error
- type DaemonStatus
- type ProcSampler
- type ProcStats
- type Server
- type ServiceOptions
Constants ¶
This section is empty.
Variables ¶
var ErrReexecRequired = errors.New("server re-exec required")
ErrReexecRequired is returned by ListenAndServe after a safe restart has checkpointed every running job. The caller starts the binary at ReexecPath in place of this process.
var ErrRestartRequired = errors.New("server restart required")
ErrRestartRequired is returned by ListenAndServe when an explicit process restart was requested (for example via the daemons API).
Functions ¶
func BearerMiddleware ¶
BearerMiddleware enforces token authentication.
Accepts:
- Authorization: Bearer <token>
- aviary_session cookie
- ?token=<token> query param (for APIs like EventSource that cannot set custom headers)
When authDisabled reports true (server.disable_token_auth), every request is let through without a token.
func GenerateToken ¶
GenerateToken creates a new random token and saves it.
func InstallService ¶
func InstallService(opts ServiceOptions) error
InstallService installs and starts a simple service for common platforms.
func LoadOrGenerateTLS ¶
func LoadOrGenerateTLS(t config.TLSConfig) (tls.Certificate, error)
LoadOrGenerateTLS loads the configured TLS cert+key, or the self-signed one, generating a new self-signed cert when none exists or the existing one is expired or does not cover every name in SelfSignedSANs.
func LoadOrGenerateToken ¶
LoadOrGenerateToken loads the stored token or generates a new one. Returns the token and a boolean indicating if it was newly generated.
func LoginHandler ¶
func LoginHandler(token string, authDisabled func() bool) http.HandlerFunc
LoginHandler handles POST /api/login — validates token, sets session cookie. When token authentication is disabled, any login succeeds without setting a session cookie.
func ReadPID ¶
ReadPID reads the PID from the PID file. Returns 0 and no error if the file does not exist.
func SelfSignedSANs ¶ added in v0.7.3
SelfSignedSANs returns the names a generated cert must cover: localhost, the loopback addresses, the hostname and the host's current non-loopback IPv4 addresses unless t.NoHostSANs is set, and t.SANs.
func SetStartupWatches ¶ added in v0.7.0
SetStartupWatches makes the next server start watch these targets without saving them to aviary.yaml.
func StartService ¶
StartService starts the named service using the platform's service manager.
func StopService ¶
StopService stops the named service using the platform's service manager.
func TLSFiles ¶ added in v0.7.3
TLSFiles returns the cert and key files the server serves with: the configured ones when set, otherwise the self-signed pair, which is generated or regenerated first when it does not cover the host's names.
func UninstallService ¶
UninstallService removes the service registration.
Types ¶
type DaemonStatus ¶
type DaemonStatus struct {
Name string `json:"name"` // display name, e.g. "aviary", "myagent/signal/0"
Type string `json:"type"` // "server", "signal", "slack", "discord"
PID int `json:"pid,omitempty"` // process ID (0 = no subprocess)
Addr string `json:"addr,omitempty"`
Started string `json:"started"`
Uptime string `json:"uptime"`
CPUPercent float64 `json:"cpu_percent"` // -1 = unavailable
RSSBytes uint64 `json:"rss_bytes"`
Status string `json:"status"` // "running", "sleeping", "gone", "error", etc.
Error string `json:"error,omitempty"` // last error message, set when status == "error"
Managed bool `json:"managed"` // true = aviary owns and monitors the process
}
DaemonStatus describes a single running daemon or integration service.
type ProcSampler ¶
type ProcSampler struct {
// contains filtered or unexported fields
}
ProcSampler periodically measures CPU% and RSS for tracked PIDs. It must be refreshed via Sample on a regular interval; callers retrieve cached values via Get without blocking.
func NewProcSampler ¶
func NewProcSampler() *ProcSampler
NewProcSampler creates an empty ProcSampler.
func (*ProcSampler) Forget ¶
func (s *ProcSampler) Forget(pid int)
Forget removes cached state for a PID that is no longer needed.
func (*ProcSampler) Get ¶
func (s *ProcSampler) Get(pid int) (ProcStats, bool)
Get returns the most recently cached stats for pid, or (zero, false) if not tracked.
func (*ProcSampler) Sample ¶
func (s *ProcSampler) Sample(pids []int)
Sample reads /proc/<pid>/stat and /proc/<pid>/statm for each PID, computes CPU% as a delta from the previous call, and caches the results.
type ProcStats ¶
type ProcStats struct {
CPUPercent float64 `json:"cpu_percent"` // CPU usage 0-100; -1 if unavailable
RSSBytes uint64 `json:"rss_bytes"` // resident set size in bytes; 0 if unavailable
Status string `json:"status"` // "running", "sleeping", "zombie", etc.
}
ProcStats holds a snapshot of process resource usage.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server wraps an HTTPS server with token auth, MCP routing, and agent management.
func (*Server) ListenAndServe ¶
ListenAndServe starts the server on the configured port. It returns only when the context is cancelled, an error occurs, or an explicit process restart is requested.
func (*Server) ReexecPath ¶ added in v0.7.0
ReexecPath is the binary to start after ListenAndServe returns ErrReexecRequired. It is resolved before an upgrade replaces the binary, because the running executable's own path can point at the moved-aside copy.
func (*Server) RestartStatus ¶ added in v0.7.0
func (s *Server) RestartStatus() saferestart.Status
RestartStatus reports the restart phase and the jobs a restart would stop.