2014-01-08 21:47:57 -05:00
|
|
|
package execdriver
|
|
|
|
|
|
|
|
import (
|
2014-01-09 18:04:45 -05:00
|
|
|
"os/exec"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
2014-01-08 21:47:57 -05:00
|
|
|
)
|
|
|
|
|
2014-01-13 18:02:12 -05:00
|
|
|
type StartCallback func(*Process)
|
|
|
|
|
2014-01-09 18:04:45 -05:00
|
|
|
type Driver interface {
|
2014-01-13 18:02:12 -05:00
|
|
|
Run(c *Process, startCallback StartCallback) (int, error) // Run executes the process and blocks until the process exits and returns the exit code
|
2014-01-09 18:04:45 -05:00
|
|
|
Kill(c *Process, sig int) error
|
2014-01-13 18:02:12 -05:00
|
|
|
// TODO: @crosbymichael @creack wait should probably return the exit code
|
|
|
|
Wait(id string, duration time.Duration) error // Wait on an out of process...process - lxc ghosts
|
2014-01-10 21:09:07 -05:00
|
|
|
Version() string
|
2014-01-13 14:13:49 -05:00
|
|
|
String() string
|
2014-01-09 18:04:45 -05:00
|
|
|
}
|
|
|
|
|
2014-01-08 21:47:57 -05:00
|
|
|
// Network settings of the container
|
|
|
|
type Network struct {
|
|
|
|
Gateway string
|
2014-01-09 19:03:22 -05:00
|
|
|
IPAddress string
|
2014-01-08 21:47:57 -05:00
|
|
|
IPPrefixLen int
|
|
|
|
Mtu int
|
|
|
|
}
|
|
|
|
|
2014-01-10 17:26:29 -05:00
|
|
|
// Process wrapps an os/exec.Cmd to add more metadata
|
2014-01-09 18:04:45 -05:00
|
|
|
type Process struct {
|
2014-01-10 14:44:35 -05:00
|
|
|
exec.Cmd
|
|
|
|
|
2014-01-10 23:22:39 -05:00
|
|
|
ID string
|
|
|
|
Privileged bool
|
|
|
|
User string
|
|
|
|
Rootfs string // root fs of the container
|
|
|
|
InitPath string // dockerinit
|
|
|
|
Entrypoint string
|
|
|
|
Arguments []string
|
|
|
|
WorkingDir string
|
|
|
|
ConfigPath string
|
|
|
|
Tty bool
|
|
|
|
Network *Network // if network is nil then networking is disabled
|
|
|
|
SysInitPath string
|
2014-01-09 18:04:45 -05:00
|
|
|
}
|
|
|
|
|
2014-01-09 21:48:34 -05:00
|
|
|
func (c *Process) Pid() int {
|
2014-01-10 14:44:35 -05:00
|
|
|
return c.Process.Pid
|
2014-01-09 18:04:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Process) GetExitCode() int {
|
2014-01-10 19:11:19 -05:00
|
|
|
if c.ProcessState == nil {
|
|
|
|
return -1
|
|
|
|
}
|
2014-01-10 14:44:35 -05:00
|
|
|
return c.ProcessState.Sys().(syscall.WaitStatus).ExitStatus()
|
2014-01-09 18:04:45 -05:00
|
|
|
}
|