Documentation
¶
Index ¶
- Constants
- func BackupServerNames() ([]string, error)
- func ContainerID(name string, client client.ContainerAPIClient) (string, error)
- func LatestServerBackup(serverName string) (string, *time.Time, error)
- func NextAvailablePort() int
- func RestoreLatestBackup(d *DockerClient) error
- type ContainerNotFoundError
- type DockerClient
- type ServerFiles
Constants ¶
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 ¶
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 ¶
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
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.