supervisor/shim: add exec support
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
78d7e8b256
commit
b4a299e61d
3 changed files with 49 additions and 4 deletions
|
@ -39,13 +39,13 @@ var execCommand = cli.Command{
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
id := time.Now().Format("2006-_2-01_15:04:05")
|
tmpDir, err := getTempDir(time.Now().Format("2006-02-01_15:04:05"))
|
||||||
tmpDir, err := getTempDir(id)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer os.RemoveAll(tmpDir)
|
defer os.RemoveAll(tmpDir)
|
||||||
|
|
||||||
|
id := context.String("id")
|
||||||
sOpts := &execution.StartProcessRequest{
|
sOpts := &execution.StartProcessRequest{
|
||||||
ContainerID: id,
|
ContainerID: id,
|
||||||
Process: &execution.Process{
|
Process: &execution.Process{
|
||||||
|
|
|
@ -117,6 +117,10 @@ var runCommand = cli.Command{
|
||||||
break eventLoop
|
break eventLoop
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if e.Type != "exit" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if e.ID == cr.Container.ID && e.Pid == cr.InitProcess.Pid {
|
if e.ID == cr.Container.ID && e.Pid == cr.InitProcess.Pid {
|
||||||
ec = e.ExitStatus
|
ec = e.ExitStatus
|
||||||
break eventLoop
|
break eventLoop
|
||||||
|
|
|
@ -172,7 +172,35 @@ func (s *Service) ResumeContainer(ctx context.Context, r *api.ResumeContainerReq
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) StartProcess(ctx context.Context, r *api.StartProcessRequest) (*api.StartProcessResponse, error) {
|
func (s *Service) StartProcess(ctx context.Context, r *api.StartProcessRequest) (*api.StartProcessResponse, error) {
|
||||||
panic("not implemented")
|
client, err := s.getShim(r.ContainerID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
er := &shim.ExecRequest{
|
||||||
|
Terminal: r.Console,
|
||||||
|
Stdin: r.Stdin,
|
||||||
|
Stdout: r.Stdout,
|
||||||
|
Stderr: r.Stderr,
|
||||||
|
Args: r.Process.Args,
|
||||||
|
Env: r.Process.Env,
|
||||||
|
Cwd: r.Process.Cwd,
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Process.User != nil {
|
||||||
|
er.User.Uid = r.Process.User.Uid
|
||||||
|
er.User.Gid = r.Process.User.Gid
|
||||||
|
er.User.AdditionalGids = r.Process.User.AdditionalGids
|
||||||
|
}
|
||||||
|
|
||||||
|
resp, err := client.Exec(ctx, er)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "failed to exec into container %q", r.ContainerID)
|
||||||
|
}
|
||||||
|
r.Process.Pid = resp.Pid
|
||||||
|
return &api.StartProcessResponse{
|
||||||
|
Process: r.Process,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// containerd managed execs + system pids forked in container
|
// containerd managed execs + system pids forked in container
|
||||||
|
@ -185,7 +213,20 @@ func (s *Service) SignalProcess(ctx context.Context, r *api.SignalProcessRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) DeleteProcess(ctx context.Context, r *api.DeleteProcessRequest) (*google_protobuf.Empty, error) {
|
func (s *Service) DeleteProcess(ctx context.Context, r *api.DeleteProcessRequest) (*google_protobuf.Empty, error) {
|
||||||
panic("not implemented")
|
client, err := s.getShim(r.ContainerID)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = client.Delete(ctx, &shim.DeleteRequest{
|
||||||
|
Pid: r.Pid,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if r.Pid == client.initPid {
|
||||||
|
s.removeShim(r.ContainerID)
|
||||||
|
}
|
||||||
|
return empty, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) ListProcesses(ctx context.Context, r *api.ListProcessesRequest) (*api.ListProcessesResponse, error) {
|
func (s *Service) ListProcesses(ctx context.Context, r *api.ListProcessesRequest) (*api.ListProcessesResponse, error) {
|
||||||
|
|
Loading…
Reference in a new issue