diff options
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/kpod/kill.go | 48 | ||||
-rw-r--r-- | cmd/kpod/stop.go | 32 |
2 files changed, 44 insertions, 36 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 diff --git a/cmd/kpod/stop.go b/cmd/kpod/stop.go index 79325da5f..78ed1216c 100644 --- a/cmd/kpod/stop.go +++ b/cmd/kpod/stop.go @@ -5,9 +5,8 @@ import ( "os" "github.com/pkg/errors" - "github.com/projectatomic/libpod/libkpod" + "github.com/sirupsen/logrus" "github.com/urfave/cli" - "golang.org/x/net/context" ) var ( @@ -47,29 +46,32 @@ func stopCmd(c *cli.Context) error { return err } - config, err := getConfig(c) + runtime, err := getRuntime(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") - } - defer server.Shutdown() - err = server.Update() - if err != nil { - return errors.Wrapf(err, "could not update list of containers") + return errors.Wrapf(err, "could not get runtime") } + defer runtime.Shutdown(false) + + logrus.Debugf("Stopping containers with timeout %d", stopTimeout) + var lastError error for _, container := range c.Args() { - cid, err := server.ContainerStop(context.Background(), container, stopTimeout) + ctr, err := runtime.LookupContainer(container) if err != nil { if lastError != nil { fmt.Fprintln(os.Stderr, lastError) } lastError = errors.Wrapf(err, "failed to stop container %v", container) + continue + } + + if err := ctr.Stop(stopTimeout); err != nil { + if lastError != nil { + fmt.Fprintln(os.Stderr, lastError) + } + lastError = errors.Wrapf(err, "failed to stop container %v", container) } else { - fmt.Println(cid) + fmt.Println(ctr.ID()) } } |