summaryrefslogtreecommitdiff
path: root/cmd/kpod/kill.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2017-11-23 14:06:43 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2017-11-29 12:15:15 +0000
commit831e2c30d479a92c203d2caf82106cb85a6cdfc8 (patch)
tree9c3970ed34441fee8990265685fbdf7654c1af51 /cmd/kpod/kill.go
parenta1d0d9f5d1d72f3ca0d1d2af36f9542f6f21ff91 (diff)
downloadpodman-831e2c30d479a92c203d2caf82106cb85a6cdfc8.tar.gz
podman-831e2c30d479a92c203d2caf82106cb85a6cdfc8.tar.bz2
podman-831e2c30d479a92c203d2caf82106cb85a6cdfc8.zip
Add ability to kill and stop containers
Also migrates kpod kill and kpod stop to libpod to use the new code Fixes force removing containers, and actually deletes containers in runc when removing them Start is now capable of starting even when the container is unmounted Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #68 Approved by: rhatdan
Diffstat (limited to 'cmd/kpod/kill.go')
-rw-r--r--cmd/kpod/kill.go48
1 files changed, 27 insertions, 21 deletions
diff --git a/cmd/kpod/kill.go b/cmd/kpod/kill.go
index 9fab7cc88..776c7ef20 100644
--- a/cmd/kpod/kill.go
+++ b/cmd/kpod/kill.go
@@ -3,10 +3,10 @@ package main
import (
"fmt"
"os"
+ "syscall"
"github.com/docker/docker/pkg/signal"
"github.com/pkg/errors"
- "github.com/projectatomic/libpod/libkpod"
"github.com/urfave/cli"
)
@@ -38,36 +38,42 @@ func killCmd(c *cli.Context) error {
if err := validateFlags(c, killFlags); err != nil {
return err
}
- config, err := getConfig(c)
- if err != nil {
- return errors.Wrapf(err, "could not get config")
- }
- server, err := libkpod.New(config)
- if err != nil {
- return errors.Wrapf(err, "could not get container server")
- }
- killSignal := c.String("signal")
- // Check if the signalString provided by the user is valid
- // Invalid signals will return err
- sysSignal, err := signal.ParseSignal(killSignal)
+
+ runtime, err := getRuntime(c)
if err != nil {
- return err
+ return errors.Wrapf(err, "could not get runtime")
}
- defer server.Shutdown()
- err = server.Update()
- if err != nil {
- return errors.Wrapf(err, "could not update list of containers")
+ defer runtime.Shutdown(false)
+
+ var killSignal uint = uint(syscall.SIGTERM)
+ if c.String("signal") != "" {
+ // Check if the signalString provided by the user is valid
+ // Invalid signals will return err
+ sysSignal, err := signal.ParseSignal(c.String("signal"))
+ if err != nil {
+ return err
+ }
+ killSignal = uint(sysSignal)
}
+
var lastError error
for _, container := range c.Args() {
- id, err := server.ContainerKill(container, sysSignal)
+ ctr, err := runtime.LookupContainer(container)
if err != nil {
if lastError != nil {
fmt.Fprintln(os.Stderr, lastError)
}
- lastError = errors.Wrapf(err, "unable to kill %v", container)
+ lastError = errors.Wrapf(err, "unable to find container %v", container)
+ continue
+ }
+
+ if err := ctr.Kill(killSignal); err != nil {
+ if lastError != nil {
+ fmt.Fprintln(os.Stderr, lastError)
+ }
+ lastError = errors.Wrapf(err, "unable to find container %v", container)
} else {
- fmt.Println(id)
+ fmt.Println(ctr.ID())
}
}
return lastError