Documentation
¶
Index ¶
- Constants
- func BuildDockerImage(serverURL string, noCache bool) error
- func DockerImageExists(c client.ImageAPIClient) (bool, error)
- type NotCraftError
- type NotFoundError
- type Server
- func (s *Server) Command(args []string) error
- func (s *Server) CommandWriter() (net.Conn, error)
- func (s *Server) HasVolume() bool
- func (s *Server) IsRunning() bool
- func (s *Server) LogReader(tail int) (*bufio.Reader, error)
- func (s *Server) Port() (int, error)
- func (s *Server) RunBedrock() error
- func (s *Server) Stop() error
- func (s *Server) StopOrPanic()
Constants ¶
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" )
Variables ¶
This section is empty.
Functions ¶
func BuildDockerImage ¶
BuildDockerImage builds the server image.
func DockerImageExists ¶
func DockerImageExists(c client.ImageAPIClient) (bool, error)
DockerImageExists returns true if the craft server image exists.
Types ¶
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 { client.ContainerAPIClient ContainerName, ContainerID string }
Server is a wrapper for docker's client.ContainerAPIClient which operates on a specific container.
func All ¶
func All(c client.ContainerAPIClient) ([]*Server, error)
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 ¶
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 ¶
Command attaches to the container and runs the given arguments separated by spaces.
func (*Server) CommandWriter ¶
CommandWriter returns a *net.Conn which streams to the container process stdin.
func (*Server) LogReader ¶
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) RunBedrock ¶
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 ¶
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.