v0.1.2 Latest Latest

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

Go to latest
Published: Aug 2, 2021 License: Apache-2.0 Imports: 22 Imported by: 0




View Source
const (
	CraftLabel = "danhale-git/craft" // Label used to identify craft servers

	ImageName = "craft_bedrock_server:autobuild" // The name of the docker image to use

	RunMCCommand = "cd bedrock; LD_LIBRARY_PATH=. ./bedrock_server"


This section is empty.


func BuildDockerImage

func BuildDockerImage(serverURL string, noCache bool) error

BuildDockerImage builds the server image.

func DockerImageExists

func DockerImageExists(c client.ImageAPIClient) (bool, error)

DockerImageExists returns true if the craft server image exists.


type NotCraftError

type NotCraftError struct {
	Name string

NotCraftError reports the instance where a container is found with a given name but lacks the label indicating that it is managed using craft.

func (*NotCraftError) Error

func (e *NotCraftError) Error() string

func (*NotCraftError) Is

func (e *NotCraftError) Is(tgt error) bool

Is implements Is(error) to support errors.Is

type NotFoundError

type NotFoundError struct {
	Name string

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

func (*NotFoundError) Error

func (e *NotFoundError) Error() string

func (*NotFoundError) Is

func (e *NotFoundError) Is(tgt error) bool

Is implements Is(error) to support errors.Is

type Server

type Server struct {
	ContainerName, ContainerID string

Server is a wrapper for docker's client.ContainerAPIClient which operates on a specific container.

func All

All returns a client for each active server.

func Get

func Get(cl client.ContainerAPIClient, containerName string) (*Server, error)

Get searches for a server with the given name (stopped or running) and checks that it has a label identifying it as a craft server. If no craft server with that name exists, an error of type NotFoundError. If the server is found but is not a craft server, an error of type NotCraftError is returned.

func New

func New(hostPort int, name string, mountVolume bool) (*Server, error)

New 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 <imageName>

If mountVolume is true, a local volume will also be mounted and autoremove will be disabled.

func (*Server) Command

func (s *Server) Command(args []string) error

Command attaches to the container and runs the given arguments separated by spaces.

func (*Server) CommandWriter

func (s *Server) CommandWriter() (net.Conn, error)

CommandWriter returns a *net.Conn which streams to the container process stdin.

func (*Server) HasVolume

func (s *Server) HasVolume() bool

func (*Server) IsRunning

func (s *Server) IsRunning() bool

func (*Server) LogReader

func (s *Server) 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. A negative tail value will result in the 'all' value being used.

func (*Server) Port

func (s *Server) Port() (int, error)

Port returns the port players use to connect to this server.

func (*Server) RunBedrock

func (s *Server) RunBedrock() error

RunBedrock runs the bedrock server process and waits for confirmation from the server that the process has started. The server should be join-able when this function returns.

func (*Server) Stop

func (s *Server) Stop() error

Stop executes a stop command first in the server process cli then on the container itself, stopping the server. The server must be saved separately to persist the world and settings.

func (*Server) StopOrPanic

func (s *Server) StopOrPanic()

StopOrPanic stops the server's container. The server process may not be stopped gracefully, call Server.Stop() to safely stop the server. If an error occurs while attempting to stop the server the program exits with a panic.

Jump to

Keyboard shortcuts

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