2015-12-01 19:56:08 +00:00
|
|
|
package runtime
|
2015-11-05 23:29:53 +00:00
|
|
|
|
2015-11-10 22:57:10 +00:00
|
|
|
import (
|
2015-12-11 01:07:21 +00:00
|
|
|
"io"
|
2015-11-10 22:57:10 +00:00
|
|
|
"os"
|
2015-12-04 00:07:53 +00:00
|
|
|
"time"
|
2015-11-10 22:57:10 +00:00
|
|
|
|
|
|
|
"github.com/opencontainers/specs"
|
|
|
|
)
|
2015-11-10 21:44:35 +00:00
|
|
|
|
|
|
|
type Process interface {
|
2015-12-11 19:56:01 +00:00
|
|
|
io.Closer
|
2016-01-06 21:32:46 +00:00
|
|
|
|
|
|
|
// ID of the process.
|
|
|
|
// This is either "init" when it is the container's init process or
|
|
|
|
// it is a user provided id for the process similar to the container id
|
|
|
|
ID() string
|
|
|
|
// Stdin returns the path the the processes stdin fifo
|
|
|
|
Stdin() string
|
|
|
|
// Stdout returns the path the the processes stdout fifo
|
|
|
|
Stdout() string
|
|
|
|
// Stderr returns the path the the processes stderr fifo
|
|
|
|
Stderr() string
|
|
|
|
// ExitFD returns the fd the provides an event when the process exits
|
|
|
|
ExitFD() int
|
|
|
|
// ExitStatus returns the exit status of the process or an error if it
|
|
|
|
// has not exited
|
|
|
|
ExitStatus() (int, error)
|
2015-11-10 22:57:10 +00:00
|
|
|
Spec() specs.Process
|
2016-01-06 21:32:46 +00:00
|
|
|
// Signal sends the provided signal to the process
|
2015-11-10 21:44:35 +00:00
|
|
|
Signal(os.Signal) error
|
2016-01-06 21:32:46 +00:00
|
|
|
// Container returns the container that the process belongs to
|
|
|
|
Container() Container
|
2015-11-10 21:44:35 +00:00
|
|
|
}
|
2015-12-04 00:07:53 +00:00
|
|
|
|
2016-01-27 22:19:10 +00:00
|
|
|
type State string
|
2015-11-12 21:40:23 +00:00
|
|
|
|
|
|
|
const (
|
2016-01-27 22:19:10 +00:00
|
|
|
Paused = State("paused")
|
|
|
|
Running = State("running")
|
2015-11-12 21:40:23 +00:00
|
|
|
)
|
|
|
|
|
2015-12-14 21:31:30 +00:00
|
|
|
type Console interface {
|
|
|
|
io.ReadWriter
|
|
|
|
io.Closer
|
|
|
|
}
|
|
|
|
|
2015-12-11 01:07:21 +00:00
|
|
|
type IO struct {
|
2015-12-15 00:47:42 +00:00
|
|
|
Stdin io.WriteCloser
|
|
|
|
Stdout io.ReadCloser
|
|
|
|
Stderr io.ReadCloser
|
2015-12-11 01:07:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (i *IO) Close() error {
|
|
|
|
var oerr error
|
|
|
|
for _, c := range []io.Closer{
|
|
|
|
i.Stdin,
|
|
|
|
i.Stdout,
|
|
|
|
i.Stderr,
|
|
|
|
} {
|
2015-12-14 21:31:30 +00:00
|
|
|
if c != nil {
|
|
|
|
if err := c.Close(); oerr == nil {
|
|
|
|
oerr = err
|
|
|
|
}
|
2015-12-11 01:07:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return oerr
|
2015-12-01 19:56:08 +00:00
|
|
|
}
|
|
|
|
|
2015-12-08 18:04:31 +00:00
|
|
|
type Stat struct {
|
|
|
|
// Timestamp is the time that the statistics where collected
|
|
|
|
Timestamp time.Time
|
|
|
|
// Data is the raw stats
|
|
|
|
// TODO: it is currently an interface because we don't know what type of exec drivers
|
|
|
|
// we will have or what the structure should look like at the moment os the containers
|
|
|
|
// can return what they want and we could marshal to json or whatever.
|
|
|
|
Data interface{}
|
|
|
|
}
|
|
|
|
|
2015-12-04 00:07:53 +00:00
|
|
|
type Checkpoint struct {
|
2015-12-04 21:35:03 +00:00
|
|
|
// Timestamp is the time that checkpoint happened
|
2015-12-07 22:47:03 +00:00
|
|
|
Timestamp time.Time
|
2015-12-04 21:35:03 +00:00
|
|
|
// Name is the name of the checkpoint
|
2015-12-07 22:47:03 +00:00
|
|
|
Name string
|
2015-12-04 21:35:03 +00:00
|
|
|
// Tcp checkpoints open tcp connections
|
2015-12-07 22:47:03 +00:00
|
|
|
Tcp bool
|
2015-12-04 21:35:03 +00:00
|
|
|
// UnixSockets persists unix sockets in the checkpoint
|
2015-12-07 22:47:03 +00:00
|
|
|
UnixSockets bool
|
2015-12-04 21:35:03 +00:00
|
|
|
// Shell persists tty sessions in the checkpoint
|
2015-12-07 22:47:03 +00:00
|
|
|
Shell bool
|
2015-12-04 21:35:03 +00:00
|
|
|
// Exit exits the container after the checkpoint is finished
|
2015-12-07 22:47:03 +00:00
|
|
|
Exit bool
|
2015-12-04 00:07:53 +00:00
|
|
|
}
|
|
|
|
|
2015-11-05 23:29:53 +00:00
|
|
|
type Container interface {
|
2015-11-12 21:40:23 +00:00
|
|
|
// ID returns the container ID
|
2015-11-06 00:40:57 +00:00
|
|
|
ID() string
|
2015-11-12 21:40:23 +00:00
|
|
|
// Path returns the path to the bundle
|
2015-11-10 19:38:26 +00:00
|
|
|
Path() string
|
2016-01-06 21:32:46 +00:00
|
|
|
// Start starts the init process of the container
|
|
|
|
Start() (Process, error)
|
|
|
|
// Delete removes the container's state and any resources
|
2015-11-05 23:29:53 +00:00
|
|
|
Delete() error
|
2016-01-06 21:32:46 +00:00
|
|
|
// Pid returns the container's init process id
|
|
|
|
// Pid() (int, error)
|
2015-11-12 21:40:23 +00:00
|
|
|
// Processes returns all the containers processes that have been added
|
2015-11-10 21:44:35 +00:00
|
|
|
Processes() ([]Process, error)
|
2015-11-12 21:40:23 +00:00
|
|
|
// State returns the containers runtime state
|
|
|
|
State() State
|
|
|
|
// Resume resumes a paused container
|
|
|
|
Resume() error
|
|
|
|
// Pause pauses a running container
|
|
|
|
Pause() error
|
2015-12-07 22:47:03 +00:00
|
|
|
// Checkpoints returns all the checkpoints for a container
|
2016-01-06 21:32:46 +00:00
|
|
|
// Checkpoints() ([]Checkpoint, error)
|
2015-12-07 22:47:03 +00:00
|
|
|
// Checkpoint creates a new checkpoint
|
2016-01-06 21:32:46 +00:00
|
|
|
// Checkpoint(Checkpoint) error
|
2015-12-07 22:47:03 +00:00
|
|
|
// DeleteCheckpoint deletes the checkpoint for the provided name
|
2016-01-06 21:32:46 +00:00
|
|
|
// DeleteCheckpoint(name string) error
|
2015-12-07 22:47:03 +00:00
|
|
|
// Restore restores the container to that of the checkpoint provided by name
|
2016-01-06 21:32:46 +00:00
|
|
|
// Restore(name string) error
|
2015-12-08 18:04:31 +00:00
|
|
|
// Stats returns realtime container stats and resource information
|
2016-01-06 21:32:46 +00:00
|
|
|
// Stats() (*Stat, error)
|
2015-12-16 00:22:53 +00:00
|
|
|
// OOM signals the channel if the container received an OOM notification
|
2016-01-06 21:32:46 +00:00
|
|
|
// OOM() (<-chan struct{}, error)
|
2015-11-05 23:29:53 +00:00
|
|
|
}
|