2017-01-12 18:15:27 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
gocontext "context"
|
2017-02-10 04:32:11 +00:00
|
|
|
"errors"
|
2017-01-12 18:15:27 +00:00
|
|
|
|
2017-02-09 07:31:26 +00:00
|
|
|
"github.com/docker/containerd/api/services/execution"
|
2017-01-12 18:15:27 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
var deleteCommand = cli.Command{
|
2017-01-25 06:16:13 +00:00
|
|
|
Name: "delete",
|
|
|
|
Usage: "delete a process from containerd store",
|
|
|
|
ArgsUsage: "CONTAINER",
|
2017-01-12 18:15:27 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "pid, p",
|
2017-01-25 06:16:13 +00:00
|
|
|
Usage: "process id to be deleted",
|
2017-01-12 18:15:27 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Action: func(context *cli.Context) error {
|
|
|
|
executionService, err := getExecutionService(context)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
id := context.Args().First()
|
|
|
|
if id == "" {
|
2017-02-10 04:32:11 +00:00
|
|
|
return errors.New("container id must be provided")
|
2017-01-12 18:15:27 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 23:36:10 +00:00
|
|
|
pid := uint32(context.Int64("pid"))
|
|
|
|
if pid != 0 {
|
2017-01-12 18:15:27 +00:00
|
|
|
_, err = executionService.DeleteProcess(gocontext.Background(), &execution.DeleteProcessRequest{
|
|
|
|
ContainerID: id,
|
2017-02-02 23:36:10 +00:00
|
|
|
Pid: pid,
|
2017-01-12 18:15:27 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-02-02 22:40:23 +00:00
|
|
|
return nil
|
2017-01-12 18:15:27 +00:00
|
|
|
}
|
|
|
|
|
2017-02-02 22:40:23 +00:00
|
|
|
if _, err := executionService.DeleteContainer(gocontext.Background(), &execution.DeleteContainerRequest{
|
2017-01-12 18:15:27 +00:00
|
|
|
ID: id,
|
|
|
|
}); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|