github.com/adxhyt/docker@v1.4.2-0.20150117221845-467b7c821390/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 // PID settings of the container 81 type Pid struct { 82 HostPid bool `json:"host_pid"` 83 } 84 85 type NetworkInterface struct { 86 Gateway string `json:"gateway"` 87 IPAddress string `json:"ip"` 88 IPPrefixLen int `json:"ip_prefix_len"` 89 MacAddress string `json:"mac"` 90 Bridge string `json:"bridge"` 91 GlobalIPv6Address string `json:"global_ipv6"` 92 LinkLocalIPv6Address string `json:"link_local_ipv6"` 93 GlobalIPv6PrefixLen int `json:"global_ipv6_prefix_len"` 94 IPv6Gateway string `json:"ipv6_gateway"` 95 } 96 97 type Resources struct { 98 Memory int64 `json:"memory"` 99 MemorySwap int64 `json:"memory_swap"` 100 CpuShares int64 `json:"cpu_shares"` 101 Cpuset string `json:"cpuset"` 102 } 103 104 type Mount struct { 105 Source string `json:"source"` 106 Destination string `json:"destination"` 107 Writable bool `json:"writable"` 108 Private bool `json:"private"` 109 Slave bool `json:"slave"` 110 } 111 112 // Describes a process that will be run inside a container. 113 type ProcessConfig struct { 114 exec.Cmd `json:"-"` 115 116 Privileged bool `json:"privileged"` 117 User string `json:"user"` 118 Tty bool `json:"tty"` 119 Entrypoint string `json:"entrypoint"` 120 Arguments []string `json:"arguments"` 121 Terminal Terminal `json:"-"` // standard or tty terminal 122 Console string `json:"-"` // dev/console path 123 } 124 125 // Process wrapps an os/exec.Cmd to add more metadata 126 type Command struct { 127 ID string `json:"id"` 128 Rootfs string `json:"rootfs"` // root fs of the container 129 ReadonlyRootfs bool `json:"readonly_rootfs"` 130 InitPath string `json:"initpath"` // dockerinit 131 WorkingDir string `json:"working_dir"` 132 ConfigPath string `json:"config_path"` // this should be able to be removed when the lxc template is moved into the driver 133 Network *Network `json:"network"` 134 Ipc *Ipc `json:"ipc"` 135 Pid *Pid `json:"pid"` 136 Resources *Resources `json:"resources"` 137 Mounts []Mount `json:"mounts"` 138 AllowedDevices []*devices.Device `json:"allowed_devices"` 139 AutoCreatedDevices []*devices.Device `json:"autocreated_devices"` 140 CapAdd []string `json:"cap_add"` 141 CapDrop []string `json:"cap_drop"` 142 ContainerPid int `json:"container_pid"` // the pid for the process inside a container 143 ProcessConfig ProcessConfig `json:"process_config"` // Describes the init process of the container. 144 ProcessLabel string `json:"process_label"` 145 MountLabel string `json:"mount_label"` 146 LxcConfig []string `json:"lxc_config"` 147 AppArmorProfile string `json:"apparmor_profile"` 148 }