libcontainer

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitFromStateDir

func InitFromStateDir(stateDir string) (err error)

InitFromStateDir initializes the container environment using the state directory. It reads the OCI specification from the state directory and then proceeds with initialization.

func PrepareSpec

func PrepareSpec(spec *specs.Spec, bundle string)

PrepareSpec ensures that the root filesystem path in the container specification is absolute. If the path is relative, it will be joined with the provided bundle path.

Types

type Container

type Container struct {
	// contains filtered or unexported fields
}

Container represents a container with its associated state and configuration.

func CreateContainer

func CreateContainer(fs *FS, id, bundle string) (c *Container, err error)

CreateContainer creates a new container using the container filesystem, id, and bundle path. It reads the container's specification, prepares it, creates the container, initializes it, and updates its state. Returns the created container

func (*Container) Init

func (c *Container) Init() (pid int, err error)

Init starts the init process. It returns the process ID (pid) of the init process.

func (*Container) State

func (c *Container) State() specs.State

State returns the current state of the container.

type ContainerFS

type ContainerFS interface {

	// Create initializes and creates a new container with the given ID, bundle path, and OCI runtime specification.
	// Returns the created container and any error encountered.
	Create(id, bundle string, spec specs.Spec) (container *Container, err error)

	// Start launches the container with the specified ID.
	// It returns any error encountered during the start process.
	Start(id string) (err error)

	// Kill sends a termination signal to the container with the specified ID.
	// It accepts a signal of type syscall.Signal and returns any error encountered.
	Kill(id string, signal syscall.Signal) (err error)

	// Remove deletes the container with the given ID.
	// It returns any error encountered during the removal process.
	Remove(id string) (err error)

	// State retrieves the current state of the container with the specified ID.
	// It returns the container's state and any error encountered.
	State(id string) (state specs.State, err error)

	// List returns a list of all containers' states.
	// It returns the list of container states and any error encountered.
	List() (containers []specs.State, err error)
}

ContainerFS defines the interface for container file system operations.

type FS

type FS struct {
	// contains filtered or unexported fields
}

FS represents a file system that manages containers.

func NewContainerFS

func NewContainerFS(rootDir string) (*FS, error)

NewContainerFS creates a new FS instance with the specified container directory. It initializes the directory structure if it does not already exist.

func (*FS) Create

func (r *FS) Create(id, bundle string, spec specs.Spec) (*Container, error)

Create initializes and creates a new container with the given ID, bundle path, and OCI runtime specification. It returns the created container and any error encountered.

func (*FS) Kill

func (r *FS) Kill(id string, signal syscall.Signal) (err error)

Kill sends a termination signal to the container with the specified ID. It returns any error encountered during the process.

func (*FS) List

func (r *FS) List() (containers []specs.State, err error)

List returns a list of all containers' states. It returns the list of container states and any error encountered.

func (*FS) Remove

func (r *FS) Remove(id string) (err error)

Remove deletes the container with the specified ID. It returns any error encountered during the removal process.

func (*FS) Start

func (r *FS) Start(id string) (err error)

Start launches the container specified by the given ID. Uses the ipc pipes to send the start signal It returns any error encountered during the start process.

func (*FS) State

func (r *FS) State(id string) (state specs.State, err error)

State retrieves the current state of the container with the specified ID. It returns the container's state and any error encountered.

type StateManager

type StateManager struct {
	// contains filtered or unexported fields
}

func LoadStateManager

func LoadStateManager(stateDir string) (*StateManager, error)

LoadStateManager loads an existing state from the state directory. It initializes a new StateManager and attempts to load the state from the state file. Returns a pointer to the StateManager and an error if loading the state fails.

func NewStateManager

func NewStateManager(stateDir string, state *specs.State) (*StateManager, error)

NewStateManager creates a new StateManager instance and updates the state file. It takes the state directory and an initial state as input. Returns a pointer to the StateManager and an error if updating the state fails.

func (*StateManager) LoadState

func (s *StateManager) LoadState() (err error)

LoadState reads the state from the state file. Returns an error if the file reading fails, or if the file does not exist.

func (*StateManager) SetBundle

func (s *StateManager) SetBundle(bundle string)

SetBundle sets the bundle path of the container

func (*StateManager) SetPid

func (s *StateManager) SetPid(pid int)

SetPid sets the PID of the container process

func (*StateManager) SetStatus

func (s *StateManager) SetStatus(state specs.ContainerState)

SetStatus sets the container status

func (*StateManager) State

func (s *StateManager) State() specs.State

State returns a copy of the current container state.

func (*StateManager) UpdateState

func (s *StateManager) UpdateState() (err error)

UpdateState writes the current state to the state file. Returns an error if the file writing fails.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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