diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2017-11-23 14:06:43 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-11-29 12:15:15 +0000 |
commit | 831e2c30d479a92c203d2caf82106cb85a6cdfc8 (patch) | |
tree | 9c3970ed34441fee8990265685fbdf7654c1af51 /cmd/kpod/stop.go | |
parent | a1d0d9f5d1d72f3ca0d1d2af36f9542f6f21ff91 (diff) | |
download | podman-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/stop.go')
-rw-r--r-- | cmd/kpod/stop.go | 32 |
1 files changed, 17 insertions, 15 deletions
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()) } } |