execution: use provided process ID for state
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
13399c1330
commit
7dd69a8597
6 changed files with 25 additions and 12 deletions
|
@ -16,6 +16,7 @@ type CreateOpts struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type StartProcessOpts struct {
|
type StartProcessOpts struct {
|
||||||
|
ID string
|
||||||
Spec specs.Process
|
Spec specs.Process
|
||||||
Console bool
|
Console bool
|
||||||
Stdin string
|
Stdin string
|
||||||
|
|
|
@ -12,6 +12,10 @@ import (
|
||||||
"github.com/docker/containerd/execution"
|
"github.com/docker/containerd/execution"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
initProcessID = "init"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrRootEmpty = errors.New("oci: runtime root cannot be an empty string")
|
ErrRootEmpty = errors.New("oci: runtime root cannot be an empty string")
|
||||||
)
|
)
|
||||||
|
@ -56,7 +60,7 @@ func (r *OCIRuntime) Create(ctx context.Context, id string, o execution.CreateOp
|
||||||
}
|
}
|
||||||
}(container)
|
}(container)
|
||||||
|
|
||||||
initProcID, initStateDir, err := container.StateDir().NewProcess()
|
initStateDir, err := container.StateDir().NewProcess(initProcessID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -80,7 +84,7 @@ func (r *OCIRuntime) Create(ctx context.Context, id string, o execution.CreateOp
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
process, err := newProcess(initProcID, pid)
|
process, err := newProcess(container, initProcessID, pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -126,7 +130,7 @@ func (r *OCIRuntime) load(runcC *runc.Container) (*execution.Container, error) {
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
process, err := newProcess(filepath.Base(d), pid)
|
process, err := newProcess(container, filepath.Base(d), pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -198,13 +202,13 @@ func (r *OCIRuntime) StartProcess(ctx context.Context, c *execution.Container, o
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
procID, procStateDir, err := c.StateDir().NewProcess()
|
procStateDir, err := c.StateDir().NewProcess(o.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.StateDir().DeleteProcess(procID)
|
c.StateDir().DeleteProcess(o.ID)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -223,7 +227,7 @@ func (r *OCIRuntime) StartProcess(ctx context.Context, c *execution.Container, o
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
process, err := newProcess(procID, pid)
|
process, err := newProcess(c, o.ID, pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,22 +7,28 @@ import (
|
||||||
"github.com/docker/containerd/execution"
|
"github.com/docker/containerd/execution"
|
||||||
)
|
)
|
||||||
|
|
||||||
func newProcess(id string, pid int) (execution.Process, error) {
|
func newProcess(c *execution.Container, id string, pid int) (execution.Process, error) {
|
||||||
proc, err := os.FindProcess(pid)
|
proc, err := os.FindProcess(pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &process{
|
return &process{
|
||||||
|
c: c,
|
||||||
id: id,
|
id: id,
|
||||||
proc: proc,
|
proc: proc,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type process struct {
|
type process struct {
|
||||||
|
c *execution.Container
|
||||||
id string
|
id string
|
||||||
proc *os.Process
|
proc *os.Process
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *process) Container() *execution.Container {
|
||||||
|
return p.c
|
||||||
|
}
|
||||||
|
|
||||||
func (p *process) ID() string {
|
func (p *process) ID() string {
|
||||||
return p.id
|
return p.id
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package execution
|
||||||
import "os"
|
import "os"
|
||||||
|
|
||||||
type Process interface {
|
type Process interface {
|
||||||
|
Container() *Container
|
||||||
ID() string
|
ID() string
|
||||||
Pid() int64
|
Pid() int64
|
||||||
//Spec() *specs.Process
|
//Spec() *specs.Process
|
||||||
|
|
|
@ -134,6 +134,7 @@ func (s *Service) StartProcess(ctx context.Context, r *api.StartProcessRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
process, err := s.executor.StartProcess(ctx, container, StartProcessOpts{
|
process, err := s.executor.StartProcess(ctx, container, StartProcessOpts{
|
||||||
|
ID: r.Process.ID,
|
||||||
Spec: spec,
|
Spec: spec,
|
||||||
Console: r.Console,
|
Console: r.Console,
|
||||||
Stdin: r.Stdin,
|
Stdin: r.Stdin,
|
||||||
|
|
|
@ -26,13 +26,13 @@ func (s StateDir) Delete() error {
|
||||||
return os.RemoveAll(string(s))
|
return os.RemoveAll(string(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s StateDir) NewProcess() (id, dir string, err error) {
|
func (s StateDir) NewProcess(id string) (dir string, err error) {
|
||||||
dir, err = ioutil.TempDir(s.processesDir(), "")
|
dir = filepath.Join(s.processesDir(), id)
|
||||||
if err != nil {
|
if err = os.Mkdir(dir, 0700); err != nil {
|
||||||
return "", "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
return filepath.Base(dir), dir, err
|
return dir, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s StateDir) ProcessDir(id string) string {
|
func (s StateDir) ProcessDir(id string) string {
|
||||||
|
|
Loading…
Reference in a new issue