Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
| ... | ... |
@@ -1,11 +1,17 @@ |
| 1 | 1 |
package execdriver |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"os/exec" |
| 5 | 6 |
"syscall" |
| 6 | 7 |
"time" |
| 7 | 8 |
) |
| 8 | 9 |
|
| 10 |
+var ( |
|
| 11 |
+ ErrNotRunning = errors.New("Process could not be started")
|
|
| 12 |
+ ErrWaitTimeoutReached = errors.New("Wait timeout reached")
|
|
| 13 |
+) |
|
| 14 |
+ |
|
| 9 | 15 |
type StartCallback func(*Process) |
| 10 | 16 |
|
| 11 | 17 |
type Driver interface {
|
| ... | ... |
@@ -19,29 +25,31 @@ type Driver interface {
|
| 19 | 19 |
|
| 20 | 20 |
// Network settings of the container |
| 21 | 21 |
type Network struct {
|
| 22 |
- Gateway string |
|
| 23 |
- IPAddress string |
|
| 24 |
- IPPrefixLen int |
|
| 25 |
- Mtu int |
|
| 22 |
+ Gateway string `json:"gateway"` |
|
| 23 |
+ IPAddress string `json:"ip"` |
|
| 24 |
+ IPPrefixLen int `json:"ip_prefix_len"` |
|
| 25 |
+ Mtu int `json:"mtu"` |
|
| 26 | 26 |
} |
| 27 | 27 |
|
| 28 | 28 |
// Process wrapps an os/exec.Cmd to add more metadata |
| 29 | 29 |
type Process struct {
|
| 30 | 30 |
exec.Cmd |
| 31 | 31 |
|
| 32 |
- ID string |
|
| 33 |
- Privileged bool |
|
| 34 |
- User string |
|
| 35 |
- Rootfs string // root fs of the container |
|
| 36 |
- InitPath string // dockerinit |
|
| 37 |
- Entrypoint string |
|
| 38 |
- Arguments []string |
|
| 39 |
- WorkingDir string |
|
| 40 |
- ConfigPath string |
|
| 41 |
- Tty bool |
|
| 42 |
- Network *Network // if network is nil then networking is disabled |
|
| 32 |
+ ID string `json:"id"` |
|
| 33 |
+ Privileged bool `json:"privileged"` |
|
| 34 |
+ User string `json:"user"` |
|
| 35 |
+ Rootfs string `json:"rootfs"` // root fs of the container |
|
| 36 |
+ InitPath string `json:"initpath"` // dockerinit |
|
| 37 |
+ Entrypoint string `json:"entrypoint"` |
|
| 38 |
+ Arguments []string `json:"arguments"` |
|
| 39 |
+ WorkingDir string `json:"working_dir"` |
|
| 40 |
+ ConfigPath string `json:"config_path"` // This should be able to be removed when the lxc template is moved into the driver |
|
| 41 |
+ Tty bool `json:"tty"` |
|
| 42 |
+ Network *Network `json:"network"` // if network is nil then networking is disabled |
|
| 43 | 43 |
} |
| 44 | 44 |
|
| 45 |
+// Return the pid of the process |
|
| 46 |
+// If the process is nil -1 will be returned |
|
| 45 | 47 |
func (c *Process) Pid() int {
|
| 46 | 48 |
if c.Process == nil {
|
| 47 | 49 |
return -1 |
| ... | ... |
@@ -49,6 +57,8 @@ func (c *Process) Pid() int {
|
| 49 | 49 |
return c.Process.Pid |
| 50 | 50 |
} |
| 51 | 51 |
|
| 52 |
+// Return the exit code of the process |
|
| 53 |
+// if the process has not exited -1 will be returned |
|
| 52 | 54 |
func (c *Process) GetExitCode() int {
|
| 53 | 55 |
if c.ProcessState == nil {
|
| 54 | 56 |
return -1 |
| ... | ... |
@@ -1,7 +1,6 @@ |
| 1 | 1 |
package lxc |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
- "errors" |
|
| 5 | 4 |
"fmt" |
| 6 | 5 |
"github.com/dotcloud/docker/execdriver" |
| 7 | 6 |
"github.com/dotcloud/docker/utils" |
| ... | ... |
@@ -14,15 +13,6 @@ import ( |
| 14 | 14 |
"time" |
| 15 | 15 |
) |
| 16 | 16 |
|
| 17 |
-const ( |
|
| 18 |
- startPath = "lxc-start" |
|
| 19 |
-) |
|
| 20 |
- |
|
| 21 |
-var ( |
|
| 22 |
- ErrNotRunning = errors.New("Process could not be started")
|
|
| 23 |
- ErrWaitTimeoutReached = errors.New("Wait timeout reached")
|
|
| 24 |
-) |
|
| 25 |
- |
|
| 26 | 17 |
type driver struct {
|
| 27 | 18 |
root string // root path for the driver to use |
| 28 | 19 |
apparmor bool |
| ... | ... |
@@ -47,7 +37,7 @@ func (d *driver) Name() string {
|
| 47 | 47 |
|
| 48 | 48 |
func (d *driver) Run(c *execdriver.Process, startCallback execdriver.StartCallback) (int, error) {
|
| 49 | 49 |
params := []string{
|
| 50 |
- startPath, |
|
| 50 |
+ "lxc-start", |
|
| 51 | 51 |
"-n", c.ID, |
| 52 | 52 |
"-f", c.ConfigPath, |
| 53 | 53 |
"--", |
| ... | ... |
@@ -155,7 +145,7 @@ func (d *driver) Wait(id string, duration time.Duration) error {
|
| 155 | 155 |
return err |
| 156 | 156 |
case <-time.After(duration): |
| 157 | 157 |
killer = true |
| 158 |
- return ErrWaitTimeoutReached |
|
| 158 |
+ return execdriver.ErrWaitTimeoutReached |
|
| 159 | 159 |
} |
| 160 | 160 |
} else {
|
| 161 | 161 |
return <-done |
| ... | ... |
@@ -214,7 +204,7 @@ func (d *driver) waitForStart(c *execdriver.Process, waitLock chan struct{}) err
|
| 214 | 214 |
} |
| 215 | 215 |
time.Sleep(50 * time.Millisecond) |
| 216 | 216 |
} |
| 217 |
- return ErrNotRunning |
|
| 217 |
+ return execdriver.ErrNotRunning |
|
| 218 | 218 |
} |
| 219 | 219 |
|
| 220 | 220 |
func (d *driver) waitLxc(id string, kill *bool) <-chan error {
|