Documentation
¶
Overview ¶
Package proto holds the service messages exchanged with the panel. It mirrors the panel's internal/agentlink/protocol.go; keep both in sync with docs/agent-protocol.md.
Index ¶
- Constants
- type AllocationSpec
- type CertRenew
- type CertRenewed
- type ConfigFileSpec
- type ConsoleCommand
- type ConsoleLines
- type CronJob
- type FileChunk
- type FileDelete
- type FileEntry
- type FileList
- type FilePath
- type FileRead
- type FileRename
- type FileWrite
- type InstallSpec
- type Limits
- type PowerRequest
- type SFTPAuth
- type SFTPLogin
- type ServiceRef
- type ServiceSpec
- type ServiceState
- type Stats
- type StopSpec
- type WebBackup
- type WebCapabilities
- type WebDatabase
- type WebDomain
- type WebLimits
- type WebsiteApp
- type WebsiteAppResult
- type WebsiteBackup
- type WebsiteBackupList
- type WebsiteDB
- type WebsiteDBList
- type WebsiteSpec
- type WebsiteStatus
Constants ¶
const ( TypeOK = "ok" TypeError = "error" TypeServiceCreate = "service.create" TypeServiceReinstall = "service.reinstall" TypeServiceDelete = "service.delete" TypeServicePower = "service.power" TypeServiceState = "service.state" )
Message types.
const ( StateInstalling = "installing" StateInstallFailed = "install_failed" StateOffline = "offline" StateStarting = "starting" StateRunning = "running" StateStopping = "stopping" StateCrashed = "crashed" )
Service states.
const ( TypeConsoleBacklog = "console.backlog" // panel -> agent: ServiceRef; reply ConsoleLines (recent output) TypeConsoleSubscribe = "console.subscribe" // panel -> agent: ServiceRef; start streaming lines and stats TypeConsoleUnsubscribe = "console.unsubscribe" // panel -> agent: ServiceRef TypeConsoleCommand = "console.command" // panel -> agent: ConsoleCommand; written to stdin TypeConsoleLine = "console.line" // agent -> panel event: ConsoleLines TypeStats = "stats" // agent -> panel event: Stats )
Console and statistics message types.
const ( TypeFilesList = "files.list" // FilePath -> FileList TypeFilesRead = "files.read" // FileRead -> FileChunk TypeFilesWrite = "files.write" // FileWrite TypeFilesMkdir = "files.mkdir" // FilePath TypeFilesRename = "files.rename" // FileRename TypeFilesDelete = "files.delete" // FileDelete )
File operations (panel -> agent). Paths are relative to the service's data directory (/home/container in the container); ".." and symlinks never lead outside it.
const ( TypeWebsiteApply = "website.apply" // panel -> agent: WebsiteSpec (create or update, idempotent) TypeWebsiteDelete = "website.delete" // panel -> agent: ServiceRef; removes the account, its files and databases TypeWebsiteStatus = "website.status" // panel -> agent: ServiceRef -> WebsiteStatus TypeWebsiteDB = "website.db" // panel -> agent: WebsiteDB -> WebsiteDBList TypeWebsiteBackup = "website.backup" // panel -> agent: WebsiteBackup -> WebsiteBackupList TypeWebsiteApp = "website.app" // panel -> agent: WebsiteApp (WordPress install, Git deploy) )
Web hosting (Phase 3). A website is one hosting account: a Linux user, its own PHP-FPM master (systemd unit with cgroup limits), Caddy site blocks, MariaDB databases and cron.
const ChunkSize = 512 << 10
ChunkSize is the largest piece of file data in one message (base64 keeps frames under 1 MiB).
const TypeCertRenew = "cert.renew"
TypeCertRenew is an agent -> panel request: CertRenew, answered with CertRenewed.
const TypeSFTPAuth = "sftp.auth"
TypeSFTPAuth is an agent -> panel request: SFTPAuth, answered with SFTPLogin.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AllocationSpec ¶
AllocationSpec is the service's IP:port.
type CertRenew ¶
type CertRenew struct {
CSR string `json:"csr"`
}
CertRenew carries a certificate request for a fresh node key.
type CertRenewed ¶
type CertRenewed struct {
Certificate string `json:"certificate"`
}
CertRenewed is the new client certificate (PEM).
type ConfigFileSpec ¶
type ConfigFileSpec struct {
Path string `json:"path"`
Parser string `json:"parser"`
Find json.RawMessage `json:"find"`
}
ConfigFileSpec is an egg config file rewrite.
type ConsoleCommand ¶
ConsoleCommand is a line typed into the server console.
type ConsoleLines ¶
ConsoleLines carries console output (newest last).
type FileChunk ¶
type FileChunk struct {
Size int64 `json:"size"` // total file size
Data []byte `json:"data"`
EOF bool `json:"eof"`
}
FileChunk is file data; Data is base64 (encoding/json does that for []byte).
type FileDelete ¶
FileDelete removes files and directories (recursively).
type FileEntry ¶
type FileEntry struct {
Name string `json:"name"`
Size int64 `json:"size"`
Mode string `json:"mode"`
ModTime int64 `json:"mod_time"` // unix seconds
IsDir bool `json:"is_dir"`
Symlink bool `json:"symlink"`
}
FileEntry is one directory entry.
type FileRead ¶
type FileRead struct {
ID string `json:"id"`
Path string `json:"path"`
Offset int64 `json:"offset"`
Length int `json:"length"`
}
FileRead asks for up to Length bytes (<= ChunkSize) at Offset.
type FileRename ¶
type FileRename struct {
ID string `json:"id"`
From string `json:"from"`
To string `json:"to"`
Overwrite bool `json:"overwrite,omitempty"`
}
FileRename moves From to To. Overwrite replaces an existing regular file at To (used to finish uploads and saves atomically); directories are never replaced.
type FileWrite ¶
type FileWrite struct {
ID string `json:"id"`
Path string `json:"path"`
Content string `json:"content,omitempty"`
Data []byte `json:"data,omitempty"`
Append bool `json:"append,omitempty"`
}
FileWrite writes Content (text) or Data (bytes); Append adds to the end instead of replacing.
type InstallSpec ¶
type InstallSpec struct {
Container string `json:"container"`
Entrypoint string `json:"entrypoint"`
Script string `json:"script"`
}
InstallSpec is the egg's install script and its container.
type Limits ¶
type Limits struct {
MemoryMB int `json:"memory_mb"`
CPUPercent int `json:"cpu_percent"`
DiskMB int `json:"disk_mb"`
PIDs int `json:"pids"`
}
Limits are container resource limits.
type PowerRequest ¶
PowerRequest is start, stop, restart or kill.
type SFTPAuth ¶
type SFTPAuth struct {
Username string `json:"username"`
Password string `json:"password"`
IP string `json:"ip"`
}
SFTPAuth asks the panel whether a username/password may open a service over SFTP.
type SFTPLogin ¶
type SFTPLogin struct {
ServiceID string `json:"service_id"`
}
SFTPLogin names the service the user may access.
type ServiceSpec ¶
type ServiceSpec struct {
ID string `json:"id"`
Image string `json:"image"`
Invocation string `json:"invocation"`
Env map[string]string `json:"env"`
Install InstallSpec `json:"install"`
Stop StopSpec `json:"stop"`
DoneMarkers []string `json:"done_markers"`
ConfigFiles []ConfigFileSpec `json:"config_files"`
Limits Limits `json:"limits"`
Allocation AllocationSpec `json:"allocation"`
// SkipInstall: the data directory was adopted from Wings (migrate-wings); a first
// create keeps the files and does not run the install script.
SkipInstall bool `json:"skip_install,omitempty"`
}
ServiceSpec is everything needed to install and run one service.
type ServiceState ¶
type ServiceState struct {
ID string `json:"id"`
State string `json:"state"`
Detail string `json:"detail,omitempty"`
}
ServiceState reports a service's state.
type Stats ¶
type Stats struct {
ID string `json:"id"`
CPUPercent float64 `json:"cpu_percent"` // 100 = one core
MemoryBytes uint64 `json:"memory_bytes"`
MemoryLimitBytes uint64 `json:"memory_limit_bytes"`
NetRxBytes uint64 `json:"net_rx_bytes"`
NetTxBytes uint64 `json:"net_tx_bytes"`
DiskBytes uint64 `json:"disk_bytes"`
}
Stats is a resource sample of a running service.
type StopSpec ¶
type StopSpec struct {
Command string `json:"command,omitempty"`
Signal string `json:"signal,omitempty"`
}
StopSpec is a stop command or a signal.
type WebBackup ¶
type WebBackup struct {
File string `json:"file"`
SizeBytes int64 `json:"size_bytes"`
CreatedAt time.Time `json:"created_at"`
}
WebBackup is one archive.
type WebCapabilities ¶
type WebCapabilities struct {
PHP []string `json:"php"`
Caddy bool `json:"caddy"`
MariaDB bool `json:"mariadb"`
}
WebCapabilities is what a node offers for web hosting (sent in hello).
type WebDatabase ¶
WebDatabase is one database.
type WebDomain ¶
type WebDomain struct {
Name string `json:"name"`
Aliases []string `json:"aliases,omitempty"`
Root string `json:"root"` // document root relative to ~/sites/<name> ("public", "." …)
TLS string `json:"tls"` // "auto" (ACME) or "internal" (Caddy's local CA, for testing)
}
WebDomain is a site of the account: files in ~/sites/<name>/, served from Root inside it.
type WebLimits ¶
type WebLimits struct {
DiskMB int `json:"disk_mb"`
MemoryMB int `json:"memory_mb"`
CPUPercent int `json:"cpu_percent"`
Processes int `json:"processes"`
}
WebLimits are the account's resources.
type WebsiteApp ¶
type WebsiteApp struct {
ID string `json:"id"`
App string `json:"app"` // wordpress | git
Domain string `json:"domain"` // one of the account's domains
// WordPress: an existing database of the account.
DBName string `json:"db_name,omitempty"`
DBPassword string `json:"db_password,omitempty"`
// Git: HTTPS repository; a first deploy clones into the domain directory, later ones pull.
Repo string `json:"repo,omitempty"`
Branch string `json:"branch,omitempty"`
}
WebsiteApp installs or deploys an application into a domain.
type WebsiteAppResult ¶
type WebsiteAppResult struct {
Message string `json:"message"`
}
WebsiteAppResult describes what happened.
type WebsiteBackup ¶
type WebsiteBackup struct {
ID string `json:"id"`
Action string `json:"action"`
File string `json:"file,omitempty"`
}
WebsiteBackup: action create, restore (File), delete (File) or list.
type WebsiteBackupList ¶
type WebsiteBackupList struct {
Backups []WebBackup `json:"backups"`
}
WebsiteBackupList lists backups in ~/backups.
type WebsiteDB ¶
type WebsiteDB struct {
ID string `json:"id"`
Action string `json:"action"`
Name string `json:"name,omitempty"`
Password string `json:"password,omitempty"`
}
WebsiteDB manages a database: action create (with password), password, delete, or list.
type WebsiteDBList ¶
type WebsiteDBList struct {
Databases []WebDatabase `json:"databases"`
}
WebsiteDBList lists the account's databases and their sizes.
type WebsiteSpec ¶
type WebsiteSpec struct {
ID string `json:"id"`
Username string `json:"username"` // Linux user, also the database name prefix
PHPVersion string `json:"php_version"`
Domains []WebDomain `json:"domains"`
Limits WebLimits `json:"limits"`
PHP map[string]string `json:"php,omitempty"` // php.ini overrides (allow-listed keys)
Cron []CronJob `json:"cron,omitempty"`
Suspended bool `json:"suspended"`
BackupsKeep int `json:"backups_keep,omitempty"`
}
WebsiteSpec describes a hosting account.