core

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: AGPL-3.0 Imports: 49 Imported by: 0

Documentation

Overview

Package core is the privileged half of Zelie. It runs as root, owns containerd, and accepts a small set of typed requests over a Unix socket. Nothing here listens on the network.

Index

Constants

View Source
const (
	InstallScriptPath = "/mnt/install/install.sh"
	InstallVolumePath = "/mnt/server"
)

Where an install container finds its script and the server's files, as Pterodactyl's installers expect them.

View Source
const DefaultSocket = "/run/zelie/core.sock"

DefaultSocket is where the core listens.

View Source
const ExternalUser = "zelie_external"

ExternalUser is the database user desktop tools sign in as. It is not the apps' user, so its password can change or go without touching them.

View Source
const (
	// MaxEditBytes is the largest file the editor opens or saves.
	MaxEditBytes = 4 << 20
)
View Source
const MaxPeek = 1 << 20

MaxPeek is the most a peek returns. It is for small text files the panel reads to learn something about a server, such as a game's manifest.

View Source
const MaxUploadChunk = 32 << 20

MaxUploadChunk is the most one piece of an upload may carry.

Variables

View Source
var SFTPRoutes = []string{
	"POST /v1/volumes/{name}/files/list",
	"POST /v1/volumes/{name}/files/stat",
	"POST /v1/volumes/{name}/files/mkdir",
	"POST /v1/volumes/{name}/files/rename",
	"POST /v1/volumes/{name}/files/remove",
	"PUT /v1/volumes/{name}/files/upload",
	"GET /v1/volumes/{name}/files/download",
}

SFTPRoutes are the only routes the SFTP process may use: the file operations of a volume, and nothing that starts, stops or configures anything. Which volume a login gets is the panel's decision.

Functions

func LoadExternal

func LoadExternal(path string) (*External, []ExternalListener, error)

LoadExternal reads the saved listeners. Start opens them.

func UsedPorts added in v0.6.0

func UsedPorts() ([]int, error)

UsedPorts returns the ports something on this machine holds: TCP ports that listen and UDP ports that are bound, on any address. A range for game servers is chosen from what is left.

Types

type Backup

type Backup = backup.Info

Backup is a backup file as the core describes it.

type BackupMeta

type BackupMeta struct {
	// Engine is the database's; empty for a backup of an app's volumes.
	Engine  string   `json:"engine"`
	Volumes []string `json:"volumes,omitempty"`
	Size    int64    `json:"size,omitempty"`
}

BackupMeta is what a backup holds, sent along with it, encrypted, so another server can tell what to restore it into.

type Builder

type Builder interface {
	Build(ctx context.Context, req build.Request, out io.Writer) (build.Result, error)
	RemoveCache(app string) error
}

Builder is what the core needs to build images.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to the core over its socket. The panel and the CLI use it.

func NewClient

func NewClient(socket string) *Client

func (*Client) AddOldKey

func (c *Client) AddOldKey(ctx context.Context, recovery string) ([]string, error)

AddOldKey adds the keys of another recovery file, and returns the public halves of the new ones.

func (*Client) AppendUpload

func (c *Client) AppendUpload(ctx context.Context, id string, offset int64, piece io.Reader) (Upload, error)

AppendUpload sends one piece of an upload, which starts at offset.

func (*Client) BackUpVolumes

func (c *Client) BackUpVolumes(ctx context.Context, app string, vols []VolumeRef, live bool) (Backup, error)

BackUpVolumes backs up an app's volumes into one archive. Live copies them while the app runs; otherwise the app must be stopped.

func (*Client) Backups

func (c *Client) Backups(ctx context.Context, app string) ([]Backup, error)

Backups lists an app's backup files, newest first.

func (*Client) Build

func (c *Client) Build(ctx context.Context, app, version string, env, sealedEnv []string, source io.Reader, out io.Writer) (build.Result, error)

Build sends source, a gzipped tar with one top-level directory, to be built for app, with the app's variables: env as NAME=value, sealedEnv sealed for the core. The build's output is written to out as it happens.

func (*Client) ClearForwards added in v0.6.0

func (c *Client) ClearForwards(ctx context.Context, app string) error

ClearForwards closes every port open to an app.

func (*Client) CompressFiles added in v0.6.0

func (c *Client) CompressFiles(ctx context.Context, ref FileRef, dir string, paths []string, name string) (string, error)

CompressFiles packs items of one folder into a .tar.gz there and returns its name.

func (*Client) CopyVolume added in v0.7.3

func (c *Client) CopyVolume(ctx context.Context, from, to string) error

CopyVolume fills the empty volume to with the files of from, owners included. Both are volumes of game servers or files apps.

func (*Client) CreateBackup

func (c *Client) CreateBackup(ctx context.Context, app, container, kind string) (Backup, error)

CreateBackup backs up a database from its running container.

func (*Client) CreateVolume

func (c *Client) CreateVolume(ctx context.Context, name string) error

CreateVolume makes an empty volume.

func (*Client) DataExport

func (c *Client) DataExport(ctx context.Context, app, container, engine string, q dataview.Query, w io.Writer) error

DataExport writes every row the query finds to w as CSV.

func (*Client) DataKey

func (c *Client) DataKey(ctx context.Context, app, container, key string) (dataview.Value, error)

DataKey reads what one Redis key holds.

func (*Client) DataKeys

func (c *Client) DataKeys(ctx context.Context, app, container, pattern, cursor string) (dataview.KeyPage, error)

DataKeys goes one step through a Redis database's keys.

func (*Client) DataRows

func (c *Client) DataRows(ctx context.Context, app, container, engine string, q dataview.Query) (dataview.Page, error)

DataRows reads a page of a table.

func (*Client) DataTables

func (c *Client) DataTables(ctx context.Context, app, container, engine string) ([]dataview.Table, error)

DataTables lists a database's tables and views, with their columns.

func (*Client) DeleteFiles added in v0.6.0

func (c *Client) DeleteFiles(ctx context.Context, ref FileRef, paths []string) error

func (*Client) DownloadBackup

func (c *Client) DownloadBackup(ctx context.Context, app, name string, w io.Writer) error

DownloadBackup copies the encrypted file to w.

func (*Client) DownloadFile added in v0.6.0

func (c *Client) DownloadFile(ctx context.Context, ref FileRef, p string) (io.ReadCloser, int64, error)

DownloadFile opens a file of a volume, which the caller closes, and says how long it is.

func (*Client) DownloadRange added in v0.7.0

func (c *Client) DownloadRange(ctx context.Context, ref FileRef, p string, offset, length int64) (io.ReadCloser, int64, error)

DownloadRange is DownloadFile for length bytes from offset, or to the end when length is negative. What lies past the end of the file is not sent.

func (*Client) ExtractFile added in v0.6.0

func (c *Client) ExtractFile(ctx context.Context, ref FileRef, p, dir string) (ExtractResult, error)

ExtractFile unpacks an archive of a volume into dir, or into the folder it is in when dir is empty.

func (*Client) FetchBackup

func (c *Client) FetchBackup(ctx context.Context, app, name string) error

FetchBackup brings a backup back from the destination onto this server.

func (*Client) Host

func (c *Client) Host(ctx context.Context) (engine.Host, error)

Host describes the server.

func (*Client) ImportUpload

func (c *Client) ImportUpload(ctx context.Context, id, kind string) (Backup, error)

ImportUpload makes a backup of a whole upload, as a dump of kind.

func (c *Client) Links(ctx context.Context, app string) ([]engine.Link, error)

Links returns the links of an app.

func (*Client) List

func (c *Client) List(ctx context.Context) ([]engine.Status, error)

func (*Client) ListFiles added in v0.6.0

func (c *Client) ListFiles(ctx context.Context, ref FileRef, dir string) (FileList, error)

ListFiles lists a folder of a volume.

func (*Client) Logs

func (c *Client) Logs(ctx context.Context, id string, follow bool, tail int64, w io.Writer) error

Logs writes a container's output to w. With tail above zero it starts at the first whole line within that many bytes of the end. With follow set it keeps streaming new output until ctx is cancelled.

func (*Client) MakeFolder added in v0.6.0

func (c *Client) MakeFolder(ctx context.Context, ref FileRef, p string) error

func (*Client) Offsite

func (c *Client) Offsite(ctx context.Context) (OffsiteInfo, error)

Offsite returns the destination backups are copied to.

func (*Client) OffsiteBackups

func (c *Client) OffsiteBackups(ctx context.Context) (OffsiteList, error)

OffsiteBackups lists the backups in the destination, and what each holds.

func (*Client) PeekVolumeFile added in v0.6.0

func (c *Client) PeekVolumeFile(ctx context.Context, volume, path string) ([]byte, error)

PeekVolumeFile returns the file at path inside a volume, which may be in use. A file that is not there is a *Error with status 404.

func (*Client) Pin added in v0.5.0

func (c *Client) Pin(ctx context.Context, image string) (string, error)

Pin returns image pinned to the digest its tag points at here.

func (*Client) PrepareVolume added in v0.6.0

func (c *Client) PrepareVolume(ctx context.Context, name string, req PrepareRequest) (PrepareResponse, error)

PrepareVolume edits a game server's config files and gives its files to the user the server runs as. The volume must not be in use.

func (*Client) PublicAddress added in v0.6.0

func (c *Client) PublicAddress(ctx context.Context) (PublicAddress, error)

PublicAddress returns the address found on the machine's network cards.

func (*Client) ReadFile added in v0.6.0

func (c *Client) ReadFile(ctx context.Context, ref FileRef, p string) ([]byte, error)

ReadFile returns a text file of a volume, up to MaxEditBytes.

func (*Client) RecoveryKey

func (c *Client) RecoveryKey(ctx context.Context, host string, w io.Writer) error

RecoveryKey returns the recovery file for the backups.

func (*Client) Remove

func (c *Client) Remove(ctx context.Context, id string) error

func (*Client) RemoveBackup

func (c *Client) RemoveBackup(ctx context.Context, app, name string) error

func (*Client) RemoveBuildCache

func (c *Client) RemoveBuildCache(ctx context.Context, app string) error

RemoveBuildCache deletes what builds of an app keep between them.

func (*Client) RemoveExternal

func (c *Client) RemoveExternal(ctx context.Context, app, engine, container string) error

RemoveExternal closes a database's loopback port and, if container is running, drops the external user.

func (*Client) RemoveFile added in v0.7.0

func (c *Client) RemoveFile(ctx context.Context, ref FileRef, p string) error

RemoveFile removes a file or an empty folder of a volume.

func (*Client) RemoveImage

func (c *Client) RemoveImage(ctx context.Context, name string) error

RemoveImage deletes an image Zelie built.

func (*Client) RemoveOffsite

func (c *Client) RemoveOffsite(ctx context.Context) error

RemoveOffsite forgets the destination; the bucket is left as it is.

func (*Client) RemoveOffsiteBackup

func (c *Client) RemoveOffsiteBackup(ctx context.Context, app, name string) error

RemoveOffsiteBackup deletes a backup's copy in the destination.

func (*Client) RemoveUpload

func (c *Client) RemoveUpload(ctx context.Context, id string) error

func (*Client) RemoveVolume

func (c *Client) RemoveVolume(ctx context.Context, name string) error

RemoveVolume deletes a volume and its files. No container may use it.

func (*Client) RenameFile added in v0.6.0

func (c *Client) RenameFile(ctx context.Context, ref FileRef, from, to string) error

func (*Client) RestoreBackup

func (c *Client) RestoreBackup(ctx context.Context, app, name, kind, container, volume string) error

RestoreBackup puts a backup back: into the running container for kinds that load in place, into the stopped database's volume for the others.

func (*Client) RestoreVolumes

func (c *Client) RestoreVolumes(ctx context.Context, app, name string, vols []VolumeRef, size int64) error

RestoreVolumes replaces the files of a stopped app's volumes with a backup's. size is how much the backup's files take, from when it was made.

func (*Client) Run

func (c *Client) Run(ctx context.Context, s engine.Spec) error

func (*Client) RunApp

func (c *Client) RunApp(ctx context.Context, s engine.Spec, sealedEnv []string, linked ...LinkedVar) (string, error)

RunApp runs a container of s.App with secret variables sealed for it, and variables made from the secrets of apps it is linked to. It returns the image that runs, pinned by digest (see engine.Pin).

func (*Client) RunInstall added in v0.6.0

func (c *Client) RunInstall(ctx context.Context, req InstallRequest) (string, error)

RunInstall starts a game server's install container and returns the image that runs, pinned by digest. Wait, Logs and Remove work on it like on any container.

func (*Client) SFTP added in v0.7.0

func (c *Client) SFTP(ctx context.Context) (SFTPStatus, error)

SFTP asks whether the SFTP socket is up, and for the host key.

func (*Client) SecretKey

func (c *Client) SecretKey(ctx context.Context) (secret.PublicKey, error)

SecretKey returns the key to seal secret variables with.

func (*Client) SetExternal

func (c *Client) SetExternal(ctx context.Context, app, engine, container string, port, target int, sealedPassword string) error

SetExternal opens a database's loopback port. With a sealed password it also makes the external user, or gives it the new password.

func (*Client) SetForwards added in v0.6.0

func (c *Client) SetForwards(ctx context.Context, app string, forwards []engine.Forward) error

SetForwards replaces the host ports open to an app's container: host port, protocol and the container's port. Traffic from outside the server goes straight to the container, not through the web proxy.

func (c *Client) SetLinks(ctx context.Context, app string, links []engine.Link) error

SetLinks replaces the links of an app: which other apps it may reach, on which port, and by what name.

func (*Client) SetOffsite

func (c *Client) SetOffsite(ctx context.Context, cfg OffsiteConfig) (OffsiteInfo, error)

SetOffsite checks a destination and saves it.

func (*Client) SetSFTPPort added in v0.7.0

func (c *Client) SetSFTPPort(ctx context.Context, port int) error

SetSFTPPort tells the core which port the SFTP socket listens on.

func (*Client) SetSFTPVolumes added in v0.7.0

func (c *Client) SetSFTPVolumes(ctx context.Context, names []string) error

SetSFTPVolumes tells the core which volumes the SFTP user may use.

func (*Client) Signal added in v0.6.0

func (c *Client) Signal(ctx context.Context, id, signal string) error

Signal sends a signal such as SIGINT to a container's main process.

func (*Client) StartUpload

func (c *Client) StartUpload(ctx context.Context, app string, size int64) (Upload, error)

StartUpload makes room for a file of size bytes for app.

func (*Client) StatFile added in v0.7.0

func (c *Client) StatFile(ctx context.Context, ref FileRef, p string) (FileEntry, error)

StatFile describes one item of a volume.

func (*Client) Stop

func (c *Client) Stop(ctx context.Context, id string, graceSeconds int) error

func (*Client) SweepImages

func (c *Client) SweepImages(ctx context.Context, keep []string) ([]string, error)

SweepImages tells the core which images are still needed. It deletes those that have not been for a week and returns their names.

func (*Client) SyncExternal

func (c *Client) SyncExternal(ctx context.Context, list []ExternalListener) error

SyncExternal makes the core's loopback ports exactly these.

func (*Client) Update added in v0.2.0

func (c *Client) Update(ctx context.Context, version string) error

Update starts an update to version. It returns once the release is downloaded and checked; the services restart after.

func (*Client) UpdateStatus added in v0.2.0

func (c *Client) UpdateStatus(ctx context.Context) (UpdateStatus, error)

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, id string) (Upload, error)

func (*Client) UploadBackup

func (c *Client) UploadBackup(ctx context.Context, app, name string, meta BackupMeta) error

UploadBackup copies a backup to the destination, with what it holds.

func (*Client) UploadFile added in v0.6.0

func (c *Client) UploadFile(ctx context.Context, ref FileRef, p string, size int64, body io.Reader) error

UploadFile stores what body carries as a file of a volume. size is its length when known, or -1.

func (*Client) Usage

func (c *Client) Usage(ctx context.Context, id string) (engine.Usage, error)

Usage reports what a running container uses.

func (*Client) UsedPorts added in v0.6.0

func (c *Client) UsedPorts(ctx context.Context) ([]int, error)

UsedPorts returns the ports in use on the server, sorted.

func (*Client) Version added in v0.2.0

func (c *Client) Version(ctx context.Context) (string, error)

Version asks the running core which version it is.

func (*Client) VolumeSizes

func (c *Client) VolumeSizes(ctx context.Context) (map[string]int64, error)

VolumeSizes returns the disk each volume takes, by name.

func (*Client) Wait

func (c *Client) Wait(ctx context.Context, id string) (int, error)

Wait waits until the container's process has exited and returns its exit code.

func (*Client) WriteFile added in v0.6.0

func (c *Client) WriteFile(ctx context.Context, ref FileRef, p string, content []byte, create bool) error

WriteFile replaces a file of a volume, or with create makes it and refuses a name that is taken.

func (*Client) WriteStdin added in v0.6.0

func (c *Client) WriteStdin(ctx context.Context, id string, data []byte) error

WriteStdin writes to a container's console. A container that is not reading it gives a *Error with status 409.

type ConfigChange added in v0.6.0

type ConfigChange struct {
	Key     string `json:"key"`
	Value   string `json:"value"`
	IfValue string `json:"if_value,omitempty"`
	// Add appends the line of a "file" parser change when it is missing.
	Add bool `json:"add,omitempty"`
}

type ConfigFile added in v0.6.0

type ConfigFile struct {
	Path    string         `json:"path"`
	Parser  string         `json:"parser"`
	Changes []ConfigChange `json:"changes"`
}

ConfigFile is a file to edit, with its values already filled in.

type Engine

type Engine interface {
	Run(ctx context.Context, s engine.Spec) error
	Stop(ctx context.Context, id string, grace time.Duration) error
	Remove(ctx context.Context, id string) error
	List(ctx context.Context) ([]engine.Status, error)
	RemoveImage(ctx context.Context, name string) error
	Images(ctx context.Context) ([]engine.Image, error)
	SetUnused(ctx context.Context, name string, since time.Time) error
	Pin(ctx context.Context, ref string) (string, error)
	Wait(ctx context.Context, id string) (uint32, error)
	WriteStdin(ctx context.Context, id string, data []byte) error
	Signal(ctx context.Context, id string, sig syscall.Signal) error
	Usage(id string) (engine.Usage, error)
	CreateVolume(name string) error
	RemoveVolume(ctx context.Context, name string) error
	VolumeSizes() (map[string]int64, error)
	Links(app string) ([]engine.Link, error)
	SetLinks(ctx context.Context, app string, links []engine.Link) error
	SetForwards(ctx context.Context, app string, forwards []engine.Forward) error
	Exec(ctx context.Context, id string, args []string, stdin io.Reader, stdout, stderr io.Writer) (uint32, error)
	OpenVolume(ctx context.Context, name string) (*os.Root, error)
	ReadVolume(name string) (*os.Root, error)
	VolumeSize(name string) (int64, error)
}

Engine is what the core needs from the container engine.

type Error

type Error struct {
	Status  int
	Message string
	// Code and Params are set for a message meant for the user.
	Code   string
	Params map[string]any
}

Error is a failure reported by the core.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Msg

func (e *Error) Msg() msg.Msg

Msg is the error as a message for the user: the core's own, when it wrote one, or else its text as it is.

type External

type External struct {
	// contains filtered or unexported fields
}

External keeps the loopback listeners, and saves them so they come back when the core restarts.

func (*External) Remove

func (x *External) Remove(app string) error

Remove closes an app's listener and the connections through it.

func (*External) Set

func (x *External) Set(l ExternalListener) error

Set opens or moves an app's listener.

func (*External) Start

func (x *External) Start(list []ExternalListener)

Start opens the saved listeners. One that cannot open is logged and left for the panel to set again.

func (*External) Sync

func (x *External) Sync(list []ExternalListener) error

Sync makes the listeners exactly list, which the panel sends when it starts.

type ExternalListener

type ExternalListener struct {
	App    string `json:"app"`
	Port   int    `json:"port"`   // on 127.0.0.1
	Target int    `json:"target"` // the database's port in its container
}

ExternalListener is one loopback port and where it leads.

type ExtractResult added in v0.6.0

type ExtractResult struct {
	Entries int   `json:"entries"`
	Bytes   int64 `json:"bytes"`
}

ExtractResult says what an unpacked archive made.

type FileEntry added in v0.6.0

type FileEntry struct {
	Name     string    `json:"name"`
	Size     int64     `json:"size"`
	Mode     string    `json:"mode"`
	Modified time.Time `json:"modified"`
	Dir      bool      `json:"dir"`
	Symlink  bool      `json:"symlink"`
	// Target is where a link points, as it is written. It is not followed.
	Target string `json:"target,omitempty"`
}

FileEntry is one item of a folder.

type FileList added in v0.6.0

type FileList struct {
	Path      string      `json:"path"`
	Entries   []FileEntry `json:"entries"`
	Truncated bool        `json:"truncated,omitempty"`
}

FileList is a folder's content, folders first.

type FileOwner added in v0.6.0

type FileOwner struct {
	UID uint32 `json:"uid"`
	GID uint32 `json:"gid"`
}

FileOwner is who the files belong to as the container sees it. The volume keeps container IDs on disk, so it is also what the files carry.

type FileRef added in v0.6.0

type FileRef struct {
	Volume string
	FileOwner
	// Room is how many more bytes the volume may take under its limit; nil
	// when that is not known.
	Room *int64
}

FileRef says which volume a file request is for and how to treat it.

type InstallRequest added in v0.6.0

type InstallRequest struct {
	ID    string `json:"id"`
	App   string `json:"app"`
	Image string `json:"image"`
	// Entrypoint is the shell that runs the script, such as bash or ash.
	Entrypoint string   `json:"entrypoint"`
	Script     string   `json:"script"`
	Env        []string `json:"env,omitempty"`
	// Volume is the server's volume, mounted at InstallVolumePath.
	Volume      string  `json:"volume"`
	Network     string  `json:"network,omitempty"`
	MemoryBytes int64   `json:"memory_bytes"`
	CPUs        float64 `json:"cpus"`
	Pids        int64   `json:"pids"`
}

InstallRequest is a game server's install container: an image that runs a script with the server's volume mounted. The panel waits for it and reads its output like any other container's.

type LinkedVar

type LinkedVar struct {
	Name string
	// Template is the value, with {secret} where the secret goes.
	Template string
	// From is the app the secret belongs to, and Sealed the secret, sealed
	// for it.
	From, Sealed string
}

LinkedVar is a variable made from a secret of another app, such as a database URL with the database's password in it.

type Offsite

type Offsite struct {
	// contains filtered or unexported fields
}

Offsite holds the destination. Its keys stay in a file only root reads: the panel can set them but never read them back, so a panel taken over cannot hand them out. Pointing the backups at another bucket gains it nothing either, since they are encrypted.

func LoadOffsite

func LoadOffsite(path string) (*Offsite, error)

LoadOffsite reads the destination saved at path, if there is one.

type OffsiteBackup

type OffsiteBackup struct {
	App     string    `json:"app"`
	Name    string    `json:"name"`
	Bytes   int64     `json:"bytes"`
	Created time.Time `json:"created"`
	// Meta is what the backup holds, when it was asked for and could be
	// read. Locked is set when it is there but no key here opens it.
	Meta   *BackupMeta `json:"meta,omitempty"`
	Locked bool        `json:"locked,omitempty"`
}

OffsiteBackup is a backup file found in the bucket.

type OffsiteConfig

type OffsiteConfig struct {
	Endpoint  string `json:"endpoint"`
	Region    string `json:"region"`
	Bucket    string `json:"bucket"`
	Prefix    string `json:"prefix"`
	AccessKey string `json:"access_key"`
	// SecretKey may be left out when changing the folder or the region;
	// the one already saved is kept.
	SecretKey string `json:"secret_key,omitempty"`
}

OffsiteConfig is where backups are copied off this server: a folder in an S3 bucket, and the keys to it.

type OffsiteInfo

type OffsiteInfo struct {
	Set       bool   `json:"set"`
	Endpoint  string `json:"endpoint,omitempty"`
	Region    string `json:"region,omitempty"`
	Bucket    string `json:"bucket,omitempty"`
	Prefix    string `json:"prefix,omitempty"`
	AccessKey string `json:"access_key,omitempty"`
}

OffsiteInfo is the destination as the panel may see it: everything but the secret key.

type OffsiteList

type OffsiteList struct {
	// Key is the public key the folder's backups were encrypted for, from
	// the note beside them, and Opens whether a key here opens them.
	Key     string          `json:"key,omitempty"`
	Opens   bool            `json:"opens"`
	Backups []OffsiteBackup `json:"backups"`
}

OffsiteList is what the destination's folder holds.

type PeekRequest added in v0.6.0

type PeekRequest struct {
	Path string `json:"path"`
}

PeekRequest names one file inside a volume.

type PeekResponse added in v0.6.0

type PeekResponse struct {
	Content []byte `json:"content"`
}

PeekResponse holds the file as it is.

type PrepareRequest added in v0.6.0

type PrepareRequest struct {
	// UID and GID are the owner as the container sees it. The volume keeps
	// container IDs on disk, so this is also what the files carry.
	UID   uint32       `json:"uid"`
	GID   uint32       `json:"gid"`
	Files []ConfigFile `json:"files,omitempty"`
}

PrepareRequest makes a game server's volume ready to start: the config files its egg asks for are edited, and every file is given to the user the server runs as. It is refused while a container of the volume runs.

type PrepareResponse added in v0.6.0

type PrepareResponse struct {
	Notes []string `json:"notes"`
}

PrepareResponse lists what could not be done. Nothing in it stops the server from starting; the panel shows it in the start's log.

type PublicAddress added in v0.6.0

type PublicAddress struct {
	Address string `json:"address"`
	Private bool   `json:"private"`
}

PublicAddress is the address players are most likely to reach this machine on. Private means no network card has a public one, so players outside the machine's network may not get through.

func DetectAddress added in v0.6.0

func DetectAddress() (PublicAddress, error)

DetectAddress reads the machine's network cards. Nothing is asked of any outside service, so it works the same behind a tunnel or offline.

type SFTPSocket added in v0.7.0

type SFTPSocket struct {
	// DropIn is the file that holds the port.
	DropIn string
	// HostKeyDir is the root-owned folder with the SFTP server's host key,
	// and User the account whose group may read it. OldKeyDir is where
	// earlier versions kept the key, in the SFTP user's own folder.
	HostKeyDir string
	OldKeyDir  string
	User       string
	// Run runs a command and returns what it printed.
	Run func(ctx context.Context, name string, args ...string) (string, error)
	// contains filtered or unexported fields
}

SFTPSocket controls the SFTP socket. The paths and the command runner are fields so tests can point them elsewhere.

func (*SFTPSocket) EnsureHostKey added in v0.7.4

func (c *SFTPSocket) EnsureHostKey() (ssh.Signer, error)

EnsureHostKey makes the host key if there is none and returns it. The core calls it at start, so a fresh install has the key before the first connection, and Status calls it again in case the key went missing.

func (*SFTPSocket) Port added in v0.7.4

func (c *SFTPSocket) Port() (int, error)

Port is the port the socket listens on: the one in the drop-in, or the unit's own when the panel never changed it.

func (*SFTPSocket) SetPort added in v0.7.0

func (c *SFTPSocket) SetPort(ctx context.Context, port int) error

SetPort makes the socket listen on port. The drop-in first clears the port the unit names, or systemd would listen on both. Nothing happens if the file already says so, so a panel that repeats itself at every start does not drop a connection. If the socket will not start on the new port, most likely because another program has it, the old port is put back so SFTP keeps working where it was.

func (*SFTPSocket) Status added in v0.7.0

func (c *SFTPSocket) Status(ctx context.Context) (SFTPStatus, error)

Status reports whether the socket is up and the host key's fingerprint. It makes the host key if there is none, so the fingerprint can be shown before anyone has connected.

type SFTPStatus added in v0.7.0

type SFTPStatus struct {
	// Listening is whether the socket is up. The server itself runs only
	// while someone is connected.
	Listening bool   `json:"listening"`
	HostKey   string `json:"host_key"`
}

SFTPStatus is what the panel learns about the SFTP server.

type SFTPVolumes added in v0.7.0

type SFTPVolumes struct {
	// contains filtered or unexported fields
}

SFTPVolumes is the list of volumes the SFTP user may use, kept in a file so it is there again when the core restarts.

func LoadSFTPVolumes added in v0.7.0

func LoadSFTPVolumes(path string) (*SFTPVolumes, error)

LoadSFTPVolumes reads the list at path. A missing file is an empty list.

func (*SFTPVolumes) Has added in v0.7.0

func (v *SFTPVolumes) Has(name string) bool

Has reports whether the SFTP user may use the volume.

func (*SFTPVolumes) Set added in v0.7.0

func (v *SFTPVolumes) Set(names []string) error

Set replaces the list and saves it.

type Server

type Server struct {
	Engine  Engine
	Builder Builder
	Secrets *secret.Keys
	Backups *backup.Dir
	Offsite *Offsite
	// External holds the loopback ports of databases open to desktop tools.
	External *External
	// Updater updates Zelie itself; nil where it cannot.
	Updater *Updater
	Paths   engine.Paths
	Log     *slog.Logger
	Allowed peer.Policy
	// SFTPUID is the user of the SFTP server, and SFTPVolumes the volumes
	// it may use. Without a user there is no such rule to apply.
	SFTPUID     uint32
	SFTPVolumes *SFTPVolumes
	// SFTPSocket holds the port and the host key of the SFTP server.
	SFTPSocket *SFTPSocket
	// Host describes the server; tests replace it.
	Host func() (engine.Host, error)
	// contains filtered or unexported fields
}

func (*Server) Handler

func (s *Server) Handler() http.Handler

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, socket string) error

Serve listens on the socket until ctx is cancelled.

func (*Server) StartExternal

func (s *Server) StartExternal(list []ExternalListener)

StartExternal opens the saved listeners once the server can find containers.

type UpdateStatus added in v0.2.0

type UpdateStatus struct {
	Version string         `json:"version"`
	Last    *update.Result `json:"last,omitempty"`
}

UpdateStatus is the running version and how the last update went.

type Updater added in v0.2.0

type Updater struct {
	// Fetch downloads a release's binary and checks its signature.
	Fetch func(ctx context.Context, version string) ([]byte, error)
	// Place puts it where the services run from, keeping the old one.
	Place func(bin []byte) error
	// Start runs the unit that restarts the services and checks them.
	Start func(ctx context.Context, from, to string) error
	// Running reports whether that unit runs now.
	Running func(ctx context.Context) bool
	// Last is the outcome of the last update.
	Last func() (update.Result, error)
	// Installed reports whether the services run from the installed binary.
	Installed func() bool
}

Updater does the parts of an update that touch the machine. Tests replace it.

type Upload

type Upload struct {
	ID       string `json:"id"`
	App      string `json:"app"`
	Size     int64  `json:"size"`
	Received int64  `json:"received"`
}

Upload is an upload in progress as the core describes it.

type VolumeRef

type VolumeRef struct {
	Name string `json:"name"`
	Dir  string `json:"dir"`
}

VolumeRef names one of an app's volumes and the folder it gets in the backup: where the app sees it, without the leading slash.

Jump to

Keyboard shortcuts

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