runtime

package
v1.20.0 Latest Latest
Warning

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

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

Documentation

Overview

Package runtime runs servers as Docker containers: one hardened container and one named volume per server. The volume holds the server's data and outlives the container; only deleting the server removes it.

Index

Constants

View Source
const (
	// Network is shared by server containers and the Agent, which checks
	// servers by their address on it.
	Network = "shardkeep-servers"

	LabelManaged = "gg.shardkeep.managed"
	LabelServer  = "gg.shardkeep.server-id"
	LabelHash    = "gg.shardkeep.config-hash"
	// LabelHashNow covers the configuration that must apply at once:
	// everything except the software and plugins, which a running server
	// takes on at its next start.
	LabelHashNow = "gg.shardkeep.config-hash-now"
	// LabelInstance marks the containers of a test Agent sharing its
	// engine with others (see instance); real Agents skip them.
	LabelInstance = "gg.shardkeep.e2e-instance"
)
View Source
const PluginsDir = ".shardkeep/plugins"

PluginsDir is where managed plugin jars are installed, relative to the server's data directory; the file manager cannot change it.

Variables

View Source
var ErrNoAddress = errors.New("the server has no address on the server network")

ErrNoAddress is returned when a running server has no address to ping.

Functions

func ContainerName

func ContainerName(serverID string) string

ContainerName and VolumeName name a server's resources.

func PingAddress

func PingAddress(inst Instance, spec Spec, publishedHost string) (string, error)

PingAddress returns where to ping a server: its address on the server network, or, when publishedHost is set, its published game port on that host (used where the Agent cannot reach the server network, as in tests against a remote Docker engine).

func PluginFile added in v1.14.0

func PluginFile(sha256 []byte) string

PluginFile is a managed plugin jar's name in PluginsDir.

func VolumeName

func VolumeName(serverID string) string

VolumeName is the server's persistent data volume.

Types

type Instance

type Instance struct {
	ContainerID string
	Running     bool
	ExitCode    int
	OOMKilled   bool
	StartedAt   time.Time
	FinishedAt  time.Time
	// IP is the container's address on Network.
	IP         string
	ConfigHash string
	// ConfigHashNow is LabelHashNow; empty for containers created before
	// it existed.
	ConfigHashNow string
}

Instance is a server's container as Docker reports it.

type Plugin added in v1.14.0

type Plugin struct {
	// Path is the verified jar in the Agent's artifact cache.
	Path   string
	SHA256 []byte
}

Plugin is one managed plugin jar.

type Port

type Port struct {
	HostPort int
	// Protocol is "tcp" or "udp".
	Protocol string
}

Port publishes the template's game port on the Node.

type Runtime

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

Runtime manages server containers.

func New

func New(c *docker.Client) *Runtime

New returns a Runtime using c.

func (*Runtime) Ensure

func (r *Runtime) Ensure(ctx context.Context, spec Spec) (created, pending bool, err error)

Ensure makes the server's volume and container match spec, creating the container, or replacing it when its configuration changed. The volume is kept. A running server whose software or plugins changed, and nothing else, is left running: the change is pending until it next starts. It reports whether a container was created and whether a change is pending.

func (*Runtime) Inspect

func (r *Runtime) Inspect(ctx context.Context, serverID string) (Instance, bool, error)

Inspect returns a server's container, or false when it has none.

func (*Runtime) Logs added in v1.12.0

func (r *Runtime) Logs(ctx context.Context, serverID string, tail int) (io.ReadCloser, error)

Logs streams a server's console output: the last tail lines, then new output until ctx ends or the server stops.

func (*Runtime) Managed

func (r *Runtime) Managed(ctx context.Context) ([]string, error)

Managed returns the IDs of servers that have a container on this Node.

func (*Runtime) Remove

func (r *Runtime) Remove(ctx context.Context, serverID string, stopTimeout time.Duration) error

Remove deletes a server's container and its data volume.

func (*Runtime) SendCommand added in v1.12.0

func (r *Runtime) SendCommand(ctx context.Context, serverID, line string) error

SendCommand types one line into a running server's console.

func (*Runtime) Setup

func (r *Runtime) Setup(ctx context.Context, self string) error

Setup creates the server network and attaches self (the Agent's own container, when it runs in one) so the Agent can reach servers.

func (*Runtime) Start

func (r *Runtime) Start(ctx context.Context, serverID string) error

Start starts a server's container.

func (*Runtime) Stop

func (r *Runtime) Stop(ctx context.Context, serverID string, timeout time.Duration) error

Stop stops a server's container gracefully, killing it after timeout.

func (*Runtime) Usage added in v1.11.0

func (r *Runtime) Usage(ctx context.Context, serverID string) (cpu time.Duration, memoryBytes int64, err error)

Usage returns a running container's total CPU time and its memory use.

func (*Runtime) Version

func (r *Runtime) Version(ctx context.Context) (string, error)

Version returns the container runtime's version.

type Spec

type Spec struct {
	ServerID    string
	Template    templates.Template
	CPUMillis   int64
	MemoryBytes int64
	Ports       []Port
	// JavaVersion selects the template's runtime image.
	JavaVersion int
	// Artifact is the path of the verified software to install, or empty.
	Artifact       string
	ArtifactSHA256 []byte
	// EULAAccepted writes eula.txt, which Minecraft servers require.
	EULAAccepted bool
	// Plugins are the verified plugin jars to install and load.
	Plugins []Plugin
	// Env is added to the template's environment (the proxy's forwarding
	// secret). It is part of the configuration hash, never of a label.
	Env []string
}

Spec is what the runtime needs to run one server.

Jump to

Keyboard shortcuts

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