docker

package
v0.0.0-...-ce8dd9f Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAttached = errors.Sentinel("not attached to instance")

Functions

This section is empty.

Types

type Environment

type Environment struct {

	// The public identifier for this environment. In this case it is the Docker container
	// name that will be used for all instances created under it.
	Id string

	// The environment configuration.
	Configuration *environment.Configuration
	// contains filtered or unexported fields
}

func New

New creates a new base Docker environment. The ID passed through will be the ID that is used to reference the container from here on out. This should be unique per-server (we use the UUID by default). The container does not need to exist at this point.

func (*Environment) Attach

func (e *Environment) Attach() error

Attach attaches to the docker container itself and ensures that we can pipe data in and out of the process stream. This should not be used for reading console data as you *will* miss important output at the beginning because of the time delay with attaching to the output.

Calling this function will poll resources for the container in the background until the provided context is canceled by the caller. Failure to cancel said context will cause background memory leaks as the goroutine will not exit.

func (*Environment) Config

func (e *Environment) Config() *environment.Configuration

Returns the environment configuration allowing a process to make modifications of the environment on the fly.

func (*Environment) Create

func (e *Environment) Create() error

Create creates a new container for the server using all of the data that is currently available for it. If the container already exists it will be returned.

func (*Environment) Destroy

func (e *Environment) Destroy() error

Destroy will remove the Docker container from the server. If the container is currently running it will be forcibly stopped by Docker.

func (*Environment) Events

func (e *Environment) Events() *events.EventBus

func (*Environment) Exists

func (e *Environment) Exists() (bool, error)

Determines if the container exists in this environment. The ID passed through should be the server UUID since containers are created utilizing the server UUID as the name and docker will work fine when using the container name as the lookup parameter in addition to the longer ID auto-assigned when the container is created.

func (*Environment) ExitState

func (e *Environment) ExitState() (uint32, bool, error)

Determine the container exit state and return the exit code and whether or not the container was killed by the OOM killer.

func (*Environment) InSituUpdate

func (e *Environment) InSituUpdate() error

InSituUpdate performs an in-place update of the Docker container's resource limits without actually making any changes to the operational state of the container. This allows memory, cpu, and IO limitations to be adjusted on the fly for individual instances.

func (*Environment) IsAttached

func (e *Environment) IsAttached() bool

Determine if the this process is currently attached to the container.

func (*Environment) IsRunning

func (e *Environment) IsRunning() (bool, error)

Determines if the server's docker container is currently running. If there is no container present, an error will be raised (since this shouldn't be a case that ever happens under correctly developed circumstances).

You can confirm if the instance wasn't found by using client.IsErrNotFound from the Docker API.

@see docker/client/errors.go

func (*Environment) OnBeforeStart

func (e *Environment) OnBeforeStart() error

Run before the container starts and get the process configuration from the Panel. This is important since we use this to check configuration files as well as ensure we always have the latest version of an egg available for server processes.

This process will also confirm that the server environment exists and is in a bootable state. This ensures that unexpected container deletion while Wings is running does not result in the server becoming un-bootable.

func (*Environment) Readlog

func (e *Environment) Readlog(lines int) ([]string, error)

Readlog reads the log file for the server. This does not care if the server is running or not, it will simply try to read the last X bytes of the file and return them.

func (*Environment) SendCommand

func (e *Environment) SendCommand(c string) error

SendCommand sends the specified command to the stdin of the running container instance. There is no confirmation that this data is sent successfully, only that it gets pushed into the stdin.

func (*Environment) SetImage

func (e *Environment) SetImage(i string)

func (*Environment) SetState

func (e *Environment) SetState(state string)

SetState sets the state of the environment. This emits an event that server's can hook into to take their own actions and track their own state based on the environment.

func (*Environment) SetStopConfiguration

func (e *Environment) SetStopConfiguration(c remote.ProcessStopConfiguration)

Sets the stop configuration for the environment.

func (*Environment) SetStream

func (e *Environment) SetStream(s *types.HijackedResponse)

Set if this process is currently attached to the process.

func (*Environment) Start

func (e *Environment) Start() error

Starts the server environment and begins piping output to the event listeners for the console. If a container does not exist, or needs to be rebuilt that will happen in the call to OnBeforeStart().

func (*Environment) State

func (e *Environment) State() string

func (*Environment) Stop

func (e *Environment) Stop() error

Stop stops the container that the server is running in. This will allow up to 30 seconds to pass before the container is forcefully terminated if we are trying to stop it without using a command sent into the instance.

You most likely want to be using WaitForStop() rather than this function, since this will return as soon as the command is sent, rather than waiting for the process to be completed stopped.

TODO: pass context through from the server instance.

func (*Environment) Terminate

func (e *Environment) Terminate(signal os.Signal) error

Terminate forcefully terminates the container using the signal provided.

func (*Environment) Type

func (e *Environment) Type() string

func (*Environment) WaitForStop

func (e *Environment) WaitForStop(seconds uint, terminate bool) error

WaitForStop attempts to gracefully stop a server using the defined stop command. If the server does not stop after seconds have passed, an error will be returned, or the instance will be terminated forcefully depending on the value of the second argument.

type Metadata

type Metadata struct {
	Image string
	Stop  remote.ProcessStopConfiguration
}

Jump to

Keyboard shortcuts

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