github.com/docker/containerd@v0.2.9-0.20170509230648-8ef7df579710/runtime/runtime.go (about)

     1  package runtime
     2  
     3  import (
     4  	"errors"
     5  	"time"
     6  
     7  	"github.com/containerd/containerd/specs"
     8  )
     9  
    10  var (
    11  	// ErrContainerExited is returned when access to an exited
    12  	// container is attempted
    13  	ErrContainerExited = errors.New("containerd: container has exited")
    14  	// ErrProcessNotExited is returned when trying to retrieve the exit
    15  	// status of an alive process
    16  	ErrProcessNotExited = errors.New("containerd: process has not exited")
    17  	// ErrContainerNotStarted is returned when a container fails to
    18  	// start without error from the shim or the OCI runtime
    19  	ErrContainerNotStarted = errors.New("containerd: container not started")
    20  	// ErrContainerStartTimeout is returned if a container takes too
    21  	// long to start
    22  	ErrContainerStartTimeout = errors.New("containerd: container did not start before the specified timeout")
    23  	// ErrShimExited is returned if the shim or the contianer's init process
    24  	// exits before completing
    25  	ErrShimExited = errors.New("containerd: shim exited before container process was started")
    26  
    27  	errNoPidFile         = errors.New("containerd: no process pid file found")
    28  	errInvalidPidInt     = errors.New("containerd: process pid is invalid")
    29  	errContainerNotFound = errors.New("containerd: container not found")
    30  	errNotImplemented    = errors.New("containerd: not implemented")
    31  )
    32  
    33  const (
    34  	// ExitFile holds the name of the pipe used to monitor process
    35  	// exit
    36  	ExitFile = "exit"
    37  	// ExitStatusFile holds the name of the file where the container
    38  	// exit code is to be written
    39  	ExitStatusFile = "exitStatus"
    40  	// StateFile holds the name of the file where the container state
    41  	// is written
    42  	StateFile = "state.json"
    43  	// ControlFile holds the name of the pipe used to control the shim
    44  	ControlFile = "control"
    45  	// InitProcessID holds the special ID used for the very first
    46  	// container's process
    47  	InitProcessID = "init"
    48  	// StartTimeFile holds the name of the file in which the process
    49  	// start time is saved
    50  	StartTimeFile = "starttime"
    51  
    52  	// UnknownStatus is the value returned when a process exit
    53  	// status cannot be determined
    54  	UnknownStatus = 255
    55  )
    56  
    57  // Checkpoint holds information regarding a container checkpoint
    58  type Checkpoint struct {
    59  	// Timestamp is the time that checkpoint happened
    60  	Created time.Time `json:"created"`
    61  	// Name is the name of the checkpoint
    62  	Name string `json:"name"`
    63  	// TCP checkpoints open tcp connections
    64  	TCP bool `json:"tcp"`
    65  	// UnixSockets persists unix sockets in the checkpoint
    66  	UnixSockets bool `json:"unixSockets"`
    67  	// Shell persists tty sessions in the checkpoint
    68  	Shell bool `json:"shell"`
    69  	// Exit exits the container after the checkpoint is finished
    70  	Exit bool `json:"exit"`
    71  	// EmptyNS tells CRIU to omit a specified namespace
    72  	EmptyNS []string `json:"emptyNS,omitempty"`
    73  }
    74  
    75  // PlatformProcessState container platform-specific fields in the ProcessState structure
    76  type PlatformProcessState struct {
    77  	Checkpoint string `json:"checkpoint"`
    78  	RootUID    int    `json:"rootUID"`
    79  	RootGID    int    `json:"rootGID"`
    80  }
    81  
    82  // State represents a container state
    83  type State string
    84  
    85  // Resource regroups the various container limits that can be updated
    86  type Resource struct {
    87  	CPUShares         int64
    88  	BlkioWeight       uint16
    89  	CPUPeriod         int64
    90  	CPUQuota          int64
    91  	CpusetCpus        string
    92  	CpusetMems        string
    93  	KernelMemory      int64
    94  	KernelTCPMemory   int64
    95  	Memory            int64
    96  	MemoryReservation int64
    97  	MemorySwap        int64
    98  	PidsLimit         int64
    99  }
   100  
   101  // Possible container states
   102  const (
   103  	Paused  = State("paused")
   104  	Stopped = State("stopped")
   105  	Running = State("running")
   106  )
   107  
   108  type state struct {
   109  	Bundle      string   `json:"bundle"`
   110  	Labels      []string `json:"labels"`
   111  	Stdin       string   `json:"stdin"`
   112  	Stdout      string   `json:"stdout"`
   113  	Stderr      string   `json:"stderr"`
   114  	Runtime     string   `json:"runtime"`
   115  	RuntimeArgs []string `json:"runtimeArgs"`
   116  	Shim        string   `json:"shim"`
   117  	NoPivotRoot bool     `json:"noPivotRoot"`
   118  }
   119  
   120  // ProcessState holds the process OCI specs along with various fields
   121  // required by containerd
   122  type ProcessState struct {
   123  	specs.ProcessSpec
   124  	Exec        bool     `json:"exec"`
   125  	Stdin       string   `json:"containerdStdin"`
   126  	Stdout      string   `json:"containerdStdout"`
   127  	Stderr      string   `json:"containerdStderr"`
   128  	RuntimeArgs []string `json:"runtimeArgs"`
   129  	NoPivotRoot bool     `json:"noPivotRoot"`
   130  
   131  	PlatformProcessState
   132  }