Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"fmt"
"os"
"path/filepath"

"github.com/codegangsta/cli"
"github.com/docker/containerd/api/grpc/types"
"github.com/hyperhq/runv/lib/linuxsignal"
netcontext "golang.org/x/net/context"
)

var deleteCommand = cli.Command{
Name: "delete",
Usage: "delete any resources held by one container or more containers often used with detached containers",
ArgsUsage: `container-id [container-id...]

Where "<container-id>" is the name for the instance of the container.

EXAMPLE:
For example, if the container id is "ubuntu01" the following will delete resources
held for "ubuntu01" removing "ubuntu01" from the runv list of containers:

# runv delete ubuntu01`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "force, f",
Usage: "[ignore on runv temporarily] forcibly kills the container if it is still running",
},
},
Action: func(context *cli.Context) {
hasError := false
if !context.Args().Present() {
fmt.Printf("runv: \"delete\" requires a minimum of 1 argument")
os.Exit(-1)
}

for _, container := range context.Args() {
c := getClient(filepath.Join(context.GlobalString("root"), container, "namespace/namespaced.sock"))
if _, err := c.Signal(netcontext.Background(), &types.SignalRequest{
Id: container,
Pid: "init",
Signal: uint32(linuxsignal.SIGKILL),
}); err != nil {
fmt.Fprintf(os.Stderr, "delete container %s failed, %v", container, err)
hasError = true
}
}

if hasError {
fmt.Errorf("one or more of the container deletions failed")
os.Exit(-1)
}
},
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func main() {
specCommand,
execCommand,
killCommand,
deleteCommand,
listCommand,
stateCommand,
manageCommand,
Expand Down