github.com/fcwu/docker@v1.4.2-0.20150115145920-2a69ca89f0df/daemon/execdriver/driver.go (about) 1 package execdriver 2 3 import ( 4 "errors" 5 "io" 6 "os" 7 "os/exec" 8 9 "github.com/docker/libcontainer/devices" 10 ) 11 12 // Context is a generic key value pair that allows 13 // arbatrary data to be sent 14 type Context map[string]string 15 16 var ( 17 ErrNotRunning = errors.New("Process could not be started") 18 ErrWaitTimeoutReached = errors.New("Wait timeout reached") 19 ErrDriverAlreadyRegistered = errors.New("A driver already registered this docker init function") 20 ErrDriverNotFound = errors.New("The requested docker init has not been found") 21 ) 22 23 type StartCallback func(*ProcessConfig, int) 24 25 // Driver specific information based on 26 // processes registered with the driver 27 type Info interface { 28 IsRunning() bool 29 } 30 31 // Terminal in an interface for drivers to implement 32 // if they want to support Close and Resize calls from 33 // the core 34 type Terminal interface { 35 io.Closer 36 Resize(height, width int) error 37 } 38 39 type TtyTerminal interface { 40 Master() *os.File 41 } 42 43 // ExitStatus provides exit reasons for a container. 44 type ExitStatus struct { 45 // The exit code with which the container exited. 46 ExitCode int 47 48 // Whether the container encountered an OOM. 49 OOMKilled bool 50 } 51 52 type Driver interface { 53 Run(c *Command, pipes *Pipes, startCallback StartCallback) (ExitStatus, error) // Run executes the process and blocks until the process exits and returns the exit code 54 // Exec executes the process in an existing container, blocks until the process exits and returns the exit code 55 Exec(c *Command, processConfig *ProcessConfig, pipes *Pipes, startCallback StartCallback) (int, error) 56 Kill(c *Command, sig int) error 57 Pause(c *Command) error 58 Unpause(c *Command) error 59 Name() string // Driver name 60 Info(id string) Info // "temporary" hack (until we move state from core to plugins) 61 GetPidsForContainer(id string) ([]int, error) // Returns a list of pids for the given container. 62 Terminate(c *Command) error // kill it with fire 63 Clean(id string) error // clean all traces of container exec 64 } 65 66 // Network settings of the container 67 type Network struct { 68 Interface *NetworkInterface `json:"interface"` // if interface is nil then networking is disabled 69 Mtu int `json:"mtu"` 70 ContainerID string `json:"container_id"` // id of the container to join network. 71 HostNetworking bool `json:"host_networking"` 72 } 73 74 // IPC settings of the container 75 type Ipc struct { 76 ContainerID string `json:"container_id"` // id of the container to join ipc. 77 HostIpc bool `json:"host_ipc"` 78 } 79 80 type NetworkInterface struct { 81 Gateway string `json:"gateway"` 82 IPAddress string `json:"ip"` 83 IPPrefixLen int `json:"ip_prefix_len"` 84 MacAddress string `json:"mac_address"` 85 Bridge string `json:"bridge"` 86 } 87 88 type Resources struct { 89 Memory int64 `json:"memory"` 90 MemorySwap int64 `json:"memory_swap"` 91 CpuShares int64 `json:"cpu_shares"` 92 Cpuset string `json:"cpuset"` 93 } 94 95 type Mount struct { 96 Source string `json:"source"` 97 Destination string `json:"destination"` 98 Writable bool `json:"writable"` 99 Private bool `json:"private"` 100 Slave bool `json:"slave"` 101 } 102 103 // Describes a process that will be run inside a container. 104 type ProcessConfig struct { 105 exec.Cmd `json:"-"` 106 107 Privileged bool `json:"privileged"` 108 User string `json:"user"` 109 Tty bool `json:"tty"` 110 Entrypoint string `json:"entrypoint"` 111 Arguments []string `json:"arguments"` 112 Terminal Terminal `json:"-"` // standard or tty terminal 113 Console string `json:"-"` // dev/console path 114 } 115 116 // Process wrapps an os/exec.Cmd to add more metadata 117 type Command struct { 118 ID string `json:"id"` 119 Rootfs string `json:"rootfs"` // root fs of the container 120 InitPath string `json:"initpath"` // dockerinit 121 WorkingDir string `json:"working_dir"` 122 ConfigPath string `json:"config_path"` // this should be able to be removed when the lxc template is moved into the driver 123 Network *Network `json:"network"` 124 Ipc *Ipc `json:"ipc"` 125 Resources *Resources `json:"resources"` 126 Mounts []Mount `json:"mounts"` 127 AllowedDevices []*devices.Device `json:"allowed_devices"` 128 AutoCreatedDevices []*devices.Device `json:"autocreated_devices"` 129 CapAdd []string `json:"cap_add"` 130 CapDrop []string `json:"cap_drop"` 131 ContainerPid int `json:"container_pid"` // the pid for the process inside a container 132 ProcessConfig ProcessConfig `json:"process_config"` // Describes the init process of the container. 133 ProcessLabel string `json:"process_label"` 134 MountLabel string `json:"mount_label"` 135 LxcConfig []string `json:"lxc_config"` 136 AppArmorProfile string `json:"apparmor_profile"` 137 }