craft

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2020 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Run the bedrock_server executable and append its output to log.txt
	RunMCCommand = "cd bedrock; LD_LIBRARY_PATH=. ./bedrock_server" // >> log.txt 2>&1"
)

Variables

This section is empty.

Functions

func BackupServerNames

func BackupServerNames() ([]string, error)

BackupServerNames returns a slice with the names of all backed up servers.

func ContainerID

func ContainerID(name string, client client.ContainerAPIClient) (string, error)

ContainerFromName returns the ID of the container with the given name or an error if that container doesn't exist.

func LatestServerBackup

func LatestServerBackup(serverName string) (string, *time.Time, error)

LatestServerBackup returns the path and backup time of the latest backup for the given server.

func NextAvailablePort

func NextAvailablePort() int

NextAvailablePort returns the next available port, starting with the default mc port. It checks the first exposed port of all running containers to determine if a port is in use.

func RestoreLatestBackup

func RestoreLatestBackup(d *DockerClient) error

RestoreLatestBackup loads backup files from disk and copies them to the DockerClient container.

Types

type ContainerNotFoundError

type ContainerNotFoundError struct {
	Name string
}

ContainerNotFoundError tells the caller that no containers were found with the given name.

func (*ContainerNotFoundError) Error

func (e *ContainerNotFoundError) Error() string

type DockerClient

type DockerClient struct {
	client.ContainerAPIClient
	ContainerName string
	// contains filtered or unexported fields
}

func ActiveServerClients

func ActiveServerClients() ([]*DockerClient, error)

ActiveServerClients returns a DockerClient for each active server.

func NewContainer

func NewContainer(hostPort int, name string) (*DockerClient, error)

NewContainer creates a new craft server container and returns a docker client for it. It is the equivalent of the following docker command:

docker run -d -e EULA=TRUE -p <HOST_PORT>:19132/udp <IMAGE_NAME>

func NewDockerClient

func NewDockerClient(containerName string) (*DockerClient, error)

NewDockerClient returns a new default Docker Container API client. If the given container name doesn't exist an error of type ContainerNotFoundError is returned.

func NewDockerClientOrExit

func NewDockerClientOrExit(containerName string) *DockerClient

NewDockerClientOrExit is a convenience function for attempting to find a docker client with the given name. If not found, a helpful error message is printed and the program exits without error.

func (*DockerClient) Command

func (d *DockerClient) Command(args []string) error

Command runs the given arguments separated by spaces as a command in the bedrock_server process cli.

func (*DockerClient) GetPort

func (d *DockerClient) GetPort() (int, error)

GetPort returns the port players use to connect to this server

func (*DockerClient) LogReader

func (d *DockerClient) LogReader(tail int) (*bufio.Reader, error)

LogReader returns a buffer with the stdout and stderr from the running mc server process. New output will continually be sent to the buffer.

func (*DockerClient) Stop

func (d *DockerClient) Stop() error

Stop stops the docker container.

type ServerFiles

type ServerFiles struct {
	Docker *DockerClient
	*files.Archive
}

ServerFiles copies files to and from the local drive and the server's file system. It requires a DockerClient associated with a valid container.

func SaveBackup

func SaveBackup(d *DockerClient) (*ServerFiles, string, error)

SaveBackup takes a backup from the server and saves it to disk. It returns a pointer to the backup data and the path it was saved to.

func (*ServerFiles) LoadFile

func (s *ServerFiles) LoadFile(localPath string) error

LoadWorld adds a file to the backup archive.

func (*ServerFiles) Restore

func (s *ServerFiles) Restore() error

Restore copies the backup files to the server.

Jump to

Keyboard shortcuts

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