42 lines
970 B
Go
42 lines
970 B
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/containerd/containerd/api/grpc/types"
|
|
"github.com/containerd/containerd/specs"
|
|
"github.com/containerd/containerd/supervisor"
|
|
"golang.org/x/net/context"
|
|
)
|
|
|
|
var clockTicksPerSecond uint64
|
|
|
|
func (s *apiServer) AddProcess(ctx context.Context, r *types.AddProcessRequest) (*types.AddProcessResponse, error) {
|
|
process := &specs.ProcessSpec{
|
|
Terminal: r.Terminal,
|
|
Args: r.Args,
|
|
Env: r.Env,
|
|
Cwd: r.Cwd,
|
|
}
|
|
if r.Id == "" {
|
|
return nil, fmt.Errorf("container id cannot be empty")
|
|
}
|
|
if r.Pid == "" {
|
|
return nil, fmt.Errorf("process id cannot be empty")
|
|
}
|
|
e := &supervisor.AddProcessTask{}
|
|
e.ID = r.Id
|
|
e.PID = r.Pid
|
|
e.ProcessSpec = process
|
|
e.Stdin = r.Stdin
|
|
e.Stdout = r.Stdout
|
|
e.Stderr = r.Stderr
|
|
e.StartResponse = make(chan supervisor.StartResponse, 1)
|
|
s.sv.SendTask(e)
|
|
if err := <-e.ErrorCh(); err != nil {
|
|
return nil, err
|
|
}
|
|
<-e.StartResponse
|
|
return &types.AddProcessResponse{}, nil
|
|
}
|