|
@@ -1,11 +1,17 @@
|
|
package execdriver
|
|
package execdriver
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
+ "errors"
|
|
"os/exec"
|
|
"os/exec"
|
|
"syscall"
|
|
"syscall"
|
|
"time"
|
|
"time"
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+var (
|
|
|
|
+ ErrNotRunning = errors.New("Process could not be started")
|
|
|
|
+ ErrWaitTimeoutReached = errors.New("Wait timeout reached")
|
|
|
|
+)
|
|
|
|
+
|
|
type StartCallback func(*Process)
|
|
type StartCallback func(*Process)
|
|
|
|
|
|
type Driver interface {
|
|
type Driver interface {
|
|
@@ -19,29 +25,31 @@ type Driver interface {
|
|
|
|
|
|
// Network settings of the container
|
|
// Network settings of the container
|
|
type Network struct {
|
|
type Network struct {
|
|
- Gateway string
|
|
|
|
- IPAddress string
|
|
|
|
- IPPrefixLen int
|
|
|
|
- Mtu int
|
|
|
|
|
|
+ Gateway string `json:"gateway"`
|
|
|
|
+ IPAddress string `json:"ip"`
|
|
|
|
+ IPPrefixLen int `json:"ip_prefix_len"`
|
|
|
|
+ Mtu int `json:"mtu"`
|
|
}
|
|
}
|
|
|
|
|
|
// Process wrapps an os/exec.Cmd to add more metadata
|
|
// Process wrapps an os/exec.Cmd to add more metadata
|
|
type Process struct {
|
|
type Process struct {
|
|
exec.Cmd
|
|
exec.Cmd
|
|
|
|
|
|
- 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
|
|
|
|
|
|
+ ID string `json:"id"`
|
|
|
|
+ Privileged bool `json:"privileged"`
|
|
|
|
+ User string `json:"user"`
|
|
|
|
+ Rootfs string `json:"rootfs"` // root fs of the container
|
|
|
|
+ InitPath string `json:"initpath"` // dockerinit
|
|
|
|
+ Entrypoint string `json:"entrypoint"`
|
|
|
|
+ Arguments []string `json:"arguments"`
|
|
|
|
+ WorkingDir string `json:"working_dir"`
|
|
|
|
+ ConfigPath string `json:"config_path"` // This should be able to be removed when the lxc template is moved into the driver
|
|
|
|
+ Tty bool `json:"tty"`
|
|
|
|
+ Network *Network `json:"network"` // if network is nil then networking is disabled
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Return the pid of the process
|
|
|
|
+// If the process is nil -1 will be returned
|
|
func (c *Process) Pid() int {
|
|
func (c *Process) Pid() int {
|
|
if c.Process == nil {
|
|
if c.Process == nil {
|
|
return -1
|
|
return -1
|
|
@@ -49,6 +57,8 @@ func (c *Process) Pid() int {
|
|
return c.Process.Pid
|
|
return c.Process.Pid
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// Return the exit code of the process
|
|
|
|
+// if the process has not exited -1 will be returned
|
|
func (c *Process) GetExitCode() int {
|
|
func (c *Process) GetExitCode() int {
|
|
if c.ProcessState == nil {
|
|
if c.ProcessState == nil {
|
|
return -1
|
|
return -1
|