2015-02-12 09:12:03 +08:00
|
|
|
// Libcontainer provides a native Go implementation for creating containers
|
|
|
|
// with namespaces, cgroups, capabilities, and filesystem access controls.
|
|
|
|
// It allows you to manage the lifecycle of the container performing additional operations
|
|
|
|
// after the container is created.
|
2014-02-19 08:56:11 +08:00
|
|
|
package libcontainer
|
|
|
|
|
2014-12-17 17:12:23 +08:00
|
|
|
import (
|
2015-08-04 07:48:19 +08:00
|
|
|
"os"
|
|
|
|
|
2015-06-22 10:29:59 +08:00
|
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
2014-12-17 17:12:23 +08:00
|
|
|
)
|
|
|
|
|
2015-02-12 08:45:23 +08:00
|
|
|
// The status of a container.
|
|
|
|
type Status int
|
|
|
|
|
|
|
|
const (
|
|
|
|
// The container exists and is running.
|
|
|
|
Running Status = iota + 1
|
|
|
|
|
|
|
|
// The container exists, it is in the process of being paused.
|
|
|
|
Pausing
|
|
|
|
|
|
|
|
// The container exists, but all its processes are paused.
|
|
|
|
Paused
|
|
|
|
|
2015-04-10 20:47:37 +08:00
|
|
|
// The container exists, but its state is saved on disk
|
|
|
|
Checkpointed
|
|
|
|
|
2015-02-12 08:45:23 +08:00
|
|
|
// The container does not exist.
|
|
|
|
Destroyed
|
|
|
|
)
|
|
|
|
|
2015-02-12 06:45:07 +08:00
|
|
|
// State represents a running container's state
|
|
|
|
type State struct {
|
2015-02-12 08:45:23 +08:00
|
|
|
// ID is the container ID.
|
|
|
|
ID string `json:"id"`
|
|
|
|
|
2015-02-12 06:45:07 +08:00
|
|
|
// InitProcessPid is the init process id in the parent namespace.
|
2015-02-12 08:45:23 +08:00
|
|
|
InitProcessPid int `json:"init_process_pid"`
|
2015-02-12 06:45:07 +08:00
|
|
|
|
|
|
|
// InitProcessStartTime is the init process start time.
|
2015-02-12 08:45:23 +08:00
|
|
|
InitProcessStartTime string `json:"init_process_start"`
|
2015-02-12 06:45:07 +08:00
|
|
|
|
|
|
|
// Path to all the cgroups setup for a container. Key is cgroup subsystem name
|
|
|
|
// with the value as the path.
|
2015-02-12 08:45:23 +08:00
|
|
|
CgroupPaths map[string]string `json:"cgroup_paths"`
|
2015-02-12 06:45:07 +08:00
|
|
|
|
2015-02-25 03:54:58 +08:00
|
|
|
// NamespacePaths are filepaths to the container's namespaces. Key is the namespace type
|
2015-02-12 06:45:07 +08:00
|
|
|
// with the value as the path.
|
2015-02-25 03:54:58 +08:00
|
|
|
NamespacePaths map[configs.NamespaceType]string `json:"namespace_paths"`
|
2015-02-12 08:45:23 +08:00
|
|
|
|
|
|
|
// Config is the container's configuration.
|
|
|
|
Config configs.Config `json:"config"`
|
2015-04-29 03:13:57 +08:00
|
|
|
|
|
|
|
// Container's standard descriptors (std{in,out,err}), needed for checkpoint and restore
|
2015-04-29 19:52:17 +08:00
|
|
|
ExternalDescriptors []string `json:"external_descriptors,omitempty"`
|
2015-02-12 06:45:07 +08:00
|
|
|
}
|
|
|
|
|
2014-10-28 08:51:14 +08:00
|
|
|
// A libcontainer container object.
|
|
|
|
//
|
|
|
|
// Each container is thread-safe within the same process. Since a container can
|
|
|
|
// be destroyed by a separate process, any function may return that the container
|
|
|
|
// was not found.
|
|
|
|
type Container interface {
|
2014-08-26 23:18:13 +08:00
|
|
|
// Returns the ID of the container
|
|
|
|
ID() string
|
2014-07-09 01:17:05 +08:00
|
|
|
|
2015-02-04 02:50:18 +08:00
|
|
|
// Returns the current status of the container.
|
2014-07-09 01:17:05 +08:00
|
|
|
//
|
2014-10-23 07:27:06 +08:00
|
|
|
// errors:
|
2015-02-12 06:45:07 +08:00
|
|
|
// ContainerDestroyed - Container no longer exists,
|
2014-10-23 07:27:06 +08:00
|
|
|
// Systemerror - System error.
|
2015-02-12 08:45:23 +08:00
|
|
|
Status() (Status, error)
|
2014-07-09 01:17:05 +08:00
|
|
|
|
2015-02-12 06:45:07 +08:00
|
|
|
// State returns the current container's state information.
|
|
|
|
//
|
|
|
|
// errors:
|
2015-04-20 10:35:51 +08:00
|
|
|
// Systemerror - System error.
|
2015-02-12 06:45:07 +08:00
|
|
|
State() (*State, error)
|
|
|
|
|
2014-07-09 01:17:05 +08:00
|
|
|
// Returns the current config of the container.
|
2015-02-01 13:21:06 +08:00
|
|
|
Config() configs.Config
|
2014-07-09 01:17:05 +08:00
|
|
|
|
2014-10-23 01:35:29 +08:00
|
|
|
// Returns the PIDs inside this container. The PIDs are in the namespace of the calling process.
|
2014-07-17 09:02:29 +08:00
|
|
|
//
|
2014-10-23 07:27:06 +08:00
|
|
|
// errors:
|
2014-09-04 07:03:41 +08:00
|
|
|
// ContainerDestroyed - Container no longer exists,
|
2014-10-23 07:27:06 +08:00
|
|
|
// Systemerror - System error.
|
2014-07-09 01:17:05 +08:00
|
|
|
//
|
2014-10-23 01:35:29 +08:00
|
|
|
// Some of the returned PIDs may no longer refer to processes in the Container, unless
|
|
|
|
// the Container state is PAUSED in which case every PID in the slice is valid.
|
2014-10-23 07:27:06 +08:00
|
|
|
Processes() ([]int, error)
|
2014-10-23 01:35:29 +08:00
|
|
|
|
|
|
|
// Returns statistics for the container.
|
2014-07-09 01:17:05 +08:00
|
|
|
//
|
2014-10-23 07:27:06 +08:00
|
|
|
// errors:
|
2014-10-23 01:35:29 +08:00
|
|
|
// ContainerDestroyed - Container no longer exists,
|
2014-10-23 07:27:06 +08:00
|
|
|
// Systemerror - System error.
|
2015-02-01 11:56:27 +08:00
|
|
|
Stats() (*Stats, error)
|
2014-10-23 01:35:29 +08:00
|
|
|
|
2015-02-27 12:09:42 +08:00
|
|
|
// Set cgroup resources of container as configured
|
|
|
|
//
|
|
|
|
// We can use this to change resources when containers are running.
|
|
|
|
//
|
|
|
|
// errors:
|
|
|
|
// Systemerror - System error.
|
2015-03-11 16:46:54 +08:00
|
|
|
Set(config configs.Config) error
|
2015-02-27 12:09:42 +08:00
|
|
|
|
2015-02-25 07:09:43 +08:00
|
|
|
// Start a process inside the container. Returns error if process fails to
|
|
|
|
// start. You can track process lifecycle with passed Process structure.
|
2014-07-09 01:17:05 +08:00
|
|
|
//
|
2014-10-23 07:27:06 +08:00
|
|
|
// errors:
|
2014-09-04 07:03:41 +08:00
|
|
|
// ContainerDestroyed - Container no longer exists,
|
2014-10-23 01:35:29 +08:00
|
|
|
// ConfigInvalid - config is invalid,
|
|
|
|
// ContainerPaused - Container is paused,
|
2014-10-23 07:27:06 +08:00
|
|
|
// Systemerror - System error.
|
2015-02-23 17:26:43 +08:00
|
|
|
Start(process *Process) (err error)
|
2014-07-09 01:17:05 +08:00
|
|
|
|
2015-03-07 03:21:02 +08:00
|
|
|
// Checkpoint checkpoints the running container's state to disk using the criu(8) utility.
|
|
|
|
//
|
|
|
|
// errors:
|
|
|
|
// Systemerror - System error.
|
2015-04-19 09:28:40 +08:00
|
|
|
Checkpoint(criuOpts *CriuOpts) error
|
2015-03-07 03:21:02 +08:00
|
|
|
|
|
|
|
// Restore restores the checkpointed container to a running state using the criu(8) utiity.
|
|
|
|
//
|
|
|
|
// errors:
|
|
|
|
// Systemerror - System error.
|
2015-04-19 09:28:40 +08:00
|
|
|
Restore(process *Process, criuOpts *CriuOpts) error
|
2015-03-07 03:21:02 +08:00
|
|
|
|
2014-10-23 01:35:29 +08:00
|
|
|
// Destroys the container after killing all running processes.
|
|
|
|
//
|
|
|
|
// Any event registrations are removed before the container is destroyed.
|
|
|
|
// No error is returned if the container is already destroyed.
|
2014-07-09 01:17:05 +08:00
|
|
|
//
|
2014-10-23 07:27:06 +08:00
|
|
|
// errors:
|
|
|
|
// Systemerror - System error.
|
|
|
|
Destroy() error
|
2014-07-09 01:17:05 +08:00
|
|
|
|
|
|
|
// If the Container state is RUNNING or PAUSING, sets the Container state to PAUSING and pauses
|
|
|
|
// the execution of any user processes. Asynchronously, when the container finished being paused the
|
|
|
|
// state is changed to PAUSED.
|
|
|
|
// If the Container state is PAUSED, do nothing.
|
|
|
|
//
|
2014-10-23 07:27:06 +08:00
|
|
|
// errors:
|
2014-09-04 07:03:41 +08:00
|
|
|
// ContainerDestroyed - Container no longer exists,
|
2014-10-23 07:27:06 +08:00
|
|
|
// Systemerror - System error.
|
|
|
|
Pause() error
|
2014-07-09 01:17:05 +08:00
|
|
|
|
|
|
|
// If the Container state is PAUSED, resumes the execution of any user processes in the
|
|
|
|
// Container before setting the Container state to RUNNING.
|
|
|
|
// If the Container state is RUNNING, do nothing.
|
|
|
|
//
|
2014-10-23 07:27:06 +08:00
|
|
|
// errors:
|
2014-09-04 07:03:41 +08:00
|
|
|
// ContainerDestroyed - Container no longer exists,
|
2014-10-23 07:27:06 +08:00
|
|
|
// Systemerror - System error.
|
|
|
|
Resume() error
|
2014-10-23 03:06:35 +08:00
|
|
|
|
2015-02-12 07:09:54 +08:00
|
|
|
// NotifyOOM returns a read-only channel signaling when the container receives an OOM notification.
|
2015-02-01 11:56:27 +08:00
|
|
|
//
|
|
|
|
// errors:
|
|
|
|
// Systemerror - System error.
|
2015-02-12 07:09:54 +08:00
|
|
|
NotifyOOM() (<-chan struct{}, error)
|
2015-08-04 07:48:19 +08:00
|
|
|
|
|
|
|
// Signal sends the provided signal code to the container's initial process.
|
|
|
|
//
|
|
|
|
// errors:
|
|
|
|
// Systemerror - System error.
|
|
|
|
Signal(s os.Signal) error
|
2014-05-17 15:06:29 +08:00
|
|
|
}
|