app

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package app ties the pieces together: the CLI and the wizard call it to install, update, run and manage instances.

Index

Constants

View Source
const DefaultBackupKeep = 10

DefaultBackupKeep is how many backups are kept when an instance doesn't say otherwise.

View Source
const UpdateHint = "Update Anyserve to get them: go install github.com/jonsjava/anyserve/cmd/anyserve@latest"

UpdateHint tells people how to get a newer Anyserve.

Variables

This section is empty.

Functions

func FormatPorts

func FormatPorts(d *spec.Definition, ports map[string]int) string

FormatPorts explains which ports to forward and which to keep private.

Types

type App

type App struct {
	Dirs  paths.Dirs
	Store instance.Store
	// Out is for normal output, Log for progress messages.
	Out io.Writer
	Log func(format string, a ...any)
}

App is the shared state for one command.

func New

func New(out io.Writer) (*App, error)

New sets up an App with the default directories.

func (*App) AddRegistry

func (a *App) AddRegistry(ctx context.Context, src registry.Source) error

AddRegistry adds and fetches an extra registry.

func (*App) Backups

func (a *App) Backups(name string) ([]Backup, error)

Backups lists an instance's backups, newest first.

func (*App) Catalog

func (a *App) Catalog() ([]Entry, []string, error)

Catalog loads every registry from the verified cache. The main registry falls back to the snapshot built into the binary. Registries that can't be loaded are reported as warnings, not errors.

func (*App) ConsoleCommand

func (a *App) ConsoleCommand(name, line string, o ConsoleOptions) (string, error)

ConsoleCommand runs one console command and returns what the server printed in reply.

func (*App) ConsoleDetails

func (a *App) ConsoleDetails(name string) (ConsoleInfo, error)

ConsoleDetails reports how to reach an instance's console.

func (*App) ConsoleSession

func (a *App) ConsoleSession(ctx context.Context, name string, o ConsoleOptions, stdin io.Reader, out io.Writer, tty bool) error

ConsoleSession is an interactive console: what the user types goes to the server, and replies (or, for the server's own console, all its output) are shown until input ends.

func (*App) Find

func (a *App) Find(ref string) (Entry, error)

Find looks a service up by id, optionally as "registry/id".

func (*App) Install

func (a *App) Install(ctx context.Context, p *Plan) (*instance.Instance, error)

Install runs a plan: download, configure, register and optionally start.

func (*App) LoadConfig

func (a *App) LoadConfig() (*Config, error)

LoadConfig reads the config file, returning an empty config if missing.

func (*App) Logs

func (a *App) Logs(name string, lines int, follow bool) error

Logs shows an instance's logs.

func (*App) MakeBackup

func (a *App) MakeBackup(name string) (Backup, error)

MakeBackup archives the definition's backup paths. If the server is running and can save on command, it's told to save first.

func (*App) PlanInstall

func (a *App) PlanInstall(req InstallRequest) (*Plan, error)

PlanInstall validates a request without changing anything.

func (*App) PortReport

func (a *App) PortReport(name string) (string, error)

PortReport describes what to forward or open for an instance.

func (*App) Reconfigure

func (a *App) Reconfigure(name string, c Changes) error

Reconfigure applies changes and restarts the instance if it was running.

func (*App) Refresh

func (a *App) Refresh(ctx context.Context) error

Refresh downloads and verifies every registry, caching the results.

func (*App) Remove

func (a *App) Remove(name string) error

Remove stops and deletes an instance. Backups are kept.

func (*App) RemoveRegistry

func (a *App) RemoveRegistry(name string) error

RemoveRegistry removes an extra registry.

func (*App) Restart

func (a *App) Restart(name string, warn time.Duration) error

Restart stops then starts an instance, warning players first if asked.

func (*App) Restore

func (a *App) Restore(name, file string) error

Restore unpacks a backup over the server files. The server must be stopped, and a safety backup of the current state is taken first.

func (*App) Run

func (a *App) Run(ctx context.Context, name string) error

Run supervises an instance in the foreground. Service managers call this.

func (*App) SaveConfig

func (a *App) SaveConfig(c *Config) error

SaveConfig writes the config file.

func (*App) Say

func (a *App) Say(name, msg string) error

Say broadcasts a chat message to players.

func (*App) Sources

func (a *App) Sources() ([]registry.Source, error)

Sources lists every configured registry, main first.

func (*App) Start

func (a *App) Start(name string) error

Start starts an instance.

func (*App) Status

func (a *App) Status(name string) (StatusLine, error)

Status reports on one instance.

func (*App) Statuses

func (a *App) Statuses() ([]StatusLine, map[string]error, error)

Statuses reports on every instance.

func (*App) SteamLogin

func (a *App) SteamLogin(ctx context.Context, user string) error

SteamLogin signs in to Steam through SteamCMD, which caches the session. Only the user name is saved; SteamCMD handles the password and Steam Guard itself.

func (*App) SteamLogout

func (a *App) SteamLogout() error

SteamLogout forgets the saved Steam user.

func (*App) Stop

func (a *App) Stop(name string) error

Stop stops an instance cleanly.

func (*App) Update

func (a *App) Update(ctx context.Context, name string, warn time.Duration, steamOutput bool) error

Update re-downloads the server, applies the newest definition from the registry, and restarts the server if it was running.

type Backup

type Backup struct {
	Path    string
	Created time.Time
	Size    int64
}

Backup is one backup file.

type Changes

type Changes struct {
	Settings map[string]string
	Ports    map[string]int
	// Expose and Unexpose open private ports to the network, or close
	// them again (stacks only).
	Expose, Unexpose []string
}

Reconfigure changes settings or ports, rewrites config files and restarts the server if it was running. Changes are what `anyserve config` can change on an instance.

type Config

type Config struct {
	// Registries are extra registries on top of the built-in main one.
	Registries []registry.Source `json:"registries,omitempty"`
	// SteamUser is the account `anyserve steam login` signed in with, for
	// servers that can't download anonymously. SteamCMD keeps the session;
	// the password is never stored here.
	SteamUser string `json:"steam_user,omitempty"`
}

Config is the user's Anyserve settings file.

type ConsoleInfo

type ConsoleInfo struct {
	Kind ConsoleKind
	// For RCON.
	Protocol string
	Port     int
	Public   bool
	Password string
	// For exec.
	Service     string
	Command     []string
	Description string
}

ConsoleInfo describes an instance's console, for `console --info`.

type ConsoleKind

type ConsoleKind string

ConsoleKind says how Anyserve reaches a server's console.

const (
	// ConsoleStdin types into the server's own console through the
	// supervisor. Replies only show up in the server's output.
	ConsoleStdin ConsoleKind = "stdin"
	// ConsoleRCON uses the server's remote console, which replies.
	ConsoleRCON ConsoleKind = "rcon"
	// ConsoleExec runs a program in one of a stack's containers.
	ConsoleExec ConsoleKind = "exec"
)

type ConsoleOptions

type ConsoleOptions struct {
	// Stdin forces the server's own console even when RCON is available.
	Stdin bool
}

ConsoleOptions picks how a console command is delivered.

type Entry

type Entry struct {
	Registry string
	Def      *spec.Definition
}

Entry is one service in the combined catalog.

type InstallRequest

type InstallRequest struct {
	Service  string // "id" or "registry/id"
	Name     string
	Target   string
	Settings map[string]string
	Ports    map[string]int
	// ServerDir overrides where server files go.
	ServerDir string
	Start     bool
	// SteamOutput shows SteamCMD's full output.
	SteamOutput bool
	// Expose opens these private ports to the network (stacks only).
	Expose []string
}

InstallRequest describes a new instance.

type NeedsNewerError

type NeedsNewerError struct {
	ID, Registry, Reason string
}

NeedsNewerError reports a service the registry offers that this version of Anyserve can't use.

func (*NeedsNewerError) Error

func (e *NeedsNewerError) Error() string

type Plan

type Plan struct {
	Req      InstallRequest
	Entry    Entry
	Target   target.Target
	Settings map[string]any
	Ports    map[string]int
	Warnings []string
}

Plan is a checked install request, ready to run. The wizard builds one first so it can show a summary before anything is downloaded.

type StatusLine

type StatusLine struct {
	Instance *instance.Instance
	Def      *spec.Definition
	Status   target.Status
	// Upgrade is the newer definition version available, if any.
	Upgrade string
}

StatusLine summarizes one instance for `list` and `status`.

Jump to

Keyboard shortcuts

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