Move exec and checkpoint to process state
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
cf28969328
commit
d317f71ac2
5 changed files with 26 additions and 31 deletions
|
@ -12,17 +12,6 @@ import (
|
||||||
"github.com/docker/docker/pkg/term"
|
"github.com/docker/docker/pkg/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
fexec bool
|
|
||||||
fcheckpoint string
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
flag.BoolVar(&fexec, "exec", false, "exec a process instead of starting the init")
|
|
||||||
flag.StringVar(&fcheckpoint, "checkpoint", "", "start container from an existing checkpoint")
|
|
||||||
flag.Parse()
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupLogger() {
|
func setupLogger() {
|
||||||
f, err := os.OpenFile("/tmp/shim.log", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0755)
|
f, err := os.OpenFile("/tmp/shim.log", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -37,6 +26,7 @@ func setupLogger() {
|
||||||
// the cwd of the shim should be the bundle for the container. Arg1 should be the path
|
// the cwd of the shim should be the bundle for the container. Arg1 should be the path
|
||||||
// to the state directory where the shim can locate fifos and other information.
|
// to the state directory where the shim can locate fifos and other information.
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
// start handling signals as soon as possible so that things are properly reaped
|
// start handling signals as soon as possible so that things are properly reaped
|
||||||
// or if runc exits before we hit the handler
|
// or if runc exits before we hit the handler
|
||||||
signals := make(chan os.Signal, 2048)
|
signals := make(chan os.Signal, 2048)
|
||||||
|
@ -56,7 +46,7 @@ func main() {
|
||||||
logrus.WithField("error", err).Fatal("shim: open control pipe")
|
logrus.WithField("error", err).Fatal("shim: open control pipe")
|
||||||
}
|
}
|
||||||
defer control.Close()
|
defer control.Close()
|
||||||
p, err := newProcess(flag.Arg(0), flag.Arg(1), fexec, fcheckpoint)
|
p, err := newProcess(flag.Arg(0), flag.Arg(1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithField("error", err).Fatal("shim: create new process")
|
logrus.WithField("error", err).Fatal("shim: create new process")
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,19 +27,18 @@ type process struct {
|
||||||
state *runtime.ProcessState
|
state *runtime.ProcessState
|
||||||
}
|
}
|
||||||
|
|
||||||
func newProcess(id, bundle string, exec bool, checkpoint string) (*process, error) {
|
func newProcess(id, bundle string) (*process, error) {
|
||||||
p := &process{
|
p := &process{
|
||||||
id: id,
|
id: id,
|
||||||
bundle: bundle,
|
bundle: bundle,
|
||||||
exec: exec,
|
|
||||||
}
|
}
|
||||||
s, err := loadProcess()
|
s, err := loadProcess()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
p.state = s
|
p.state = s
|
||||||
if checkpoint != "" {
|
if s.Checkpoint != "" {
|
||||||
cpt, err := loadCheckpoint(bundle, checkpoint)
|
cpt, err := loadCheckpoint(bundle, s.Checkpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -83,7 +82,7 @@ func (p *process) start() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
args := []string{}
|
args := []string{}
|
||||||
if p.exec {
|
if p.state.Exec {
|
||||||
args = append(args, "exec",
|
args = append(args, "exec",
|
||||||
"--process", filepath.Join(cwd, "process.json"),
|
"--process", filepath.Join(cwd, "process.json"),
|
||||||
"--console", p.consolePath,
|
"--console", p.consolePath,
|
||||||
|
@ -146,7 +145,7 @@ func (p *process) pid() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *process) delete() error {
|
func (p *process) delete() error {
|
||||||
if !p.exec {
|
if !p.state.Exec {
|
||||||
return exec.Command("runc", "delete", p.id).Run()
|
return exec.Command("runc", "delete", p.id).Run()
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -150,7 +150,6 @@ func (c *container) Start(checkpoint string, s Stdio) (Process, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cmd := exec.Command("containerd-shim",
|
cmd := exec.Command("containerd-shim",
|
||||||
"-checkpoint", checkpoint,
|
|
||||||
c.id, c.bundle,
|
c.id, c.bundle,
|
||||||
)
|
)
|
||||||
cmd.Dir = processRoot
|
cmd.Dir = processRoot
|
||||||
|
@ -162,6 +161,7 @@ func (c *container) Start(checkpoint string, s Stdio) (Process, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
config := &processConfig{
|
config := &processConfig{
|
||||||
|
checkpoint: checkpoint,
|
||||||
root: processRoot,
|
root: processRoot,
|
||||||
id: InitProcessID,
|
id: InitProcessID,
|
||||||
c: c,
|
c: c,
|
||||||
|
@ -189,7 +189,6 @@ func (c *container) Exec(pid string, spec specs.Process, s Stdio) (Process, erro
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
cmd := exec.Command("containerd-shim",
|
cmd := exec.Command("containerd-shim",
|
||||||
"-exec",
|
|
||||||
c.id, c.bundle,
|
c.id, c.bundle,
|
||||||
)
|
)
|
||||||
cmd.Dir = processRoot
|
cmd.Dir = processRoot
|
||||||
|
@ -197,6 +196,7 @@ func (c *container) Exec(pid string, spec specs.Process, s Stdio) (Process, erro
|
||||||
Setpgid: true,
|
Setpgid: true,
|
||||||
}
|
}
|
||||||
config := &processConfig{
|
config := &processConfig{
|
||||||
|
exec: true,
|
||||||
id: pid,
|
id: pid,
|
||||||
root: processRoot,
|
root: processRoot,
|
||||||
c: c,
|
c: c,
|
||||||
|
|
|
@ -47,6 +47,8 @@ type processConfig struct {
|
||||||
spec *specs.LinuxSpec
|
spec *specs.LinuxSpec
|
||||||
c *container
|
c *container
|
||||||
stdio Stdio
|
stdio Stdio
|
||||||
|
exec bool
|
||||||
|
checkpoint string
|
||||||
}
|
}
|
||||||
|
|
||||||
func newProcess(config *processConfig) (*process, error) {
|
func newProcess(config *processConfig) (*process, error) {
|
||||||
|
@ -68,6 +70,8 @@ func newProcess(config *processConfig) (*process, error) {
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
if err := json.NewEncoder(f).Encode(ProcessState{
|
if err := json.NewEncoder(f).Encode(ProcessState{
|
||||||
Process: config.processSpec,
|
Process: config.processSpec,
|
||||||
|
Exec: config.exec,
|
||||||
|
Checkpoint: config.checkpoint,
|
||||||
RootUID: uid,
|
RootUID: uid,
|
||||||
RootGID: gid,
|
RootGID: gid,
|
||||||
Stdin: config.stdio.Stdin,
|
Stdin: config.stdio.Stdin,
|
||||||
|
|
|
@ -44,6 +44,8 @@ type state struct {
|
||||||
|
|
||||||
type ProcessState struct {
|
type ProcessState struct {
|
||||||
specs.Process
|
specs.Process
|
||||||
|
Exec bool `json:"exec"`
|
||||||
|
Checkpoint string `json:"checkpoint"`
|
||||||
RootUID int `json:"rootUID"`
|
RootUID int `json:"rootUID"`
|
||||||
RootGID int `json:"rootGID"`
|
RootGID int `json:"rootGID"`
|
||||||
Stdin string `json:"containerdStdin"`
|
Stdin string `json:"containerdStdin"`
|
||||||
|
|
Loading…
Reference in a new issue