aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/start.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/start.go')
-rw-r--r--cmd/podman/start.go104
1 files changed, 5 insertions, 99 deletions
diff --git a/cmd/podman/start.go b/cmd/podman/start.go
index ec05ce90e..9f93061f9 100644
--- a/cmd/podman/start.go
+++ b/cmd/podman/start.go
@@ -1,16 +1,11 @@
package main
import (
- "fmt"
- "os"
-
"github.com/containers/libpod/cmd/podman/cliconfig"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/adapter"
- opentracing "github.com/opentracing/opentracing-go"
+ "github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
- "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
@@ -48,7 +43,7 @@ func init() {
}
func startCmd(c *cliconfig.StartValues) error {
- if c.Bool("trace") {
+ if !remoteclient && c.Bool("trace") {
span, _ := opentracing.StartSpanFromContext(Ctx, "startCmd")
defer span.Finish()
}
@@ -70,100 +65,11 @@ func startCmd(c *cliconfig.StartValues) error {
return errors.Wrapf(libpod.ErrInvalidArg, "you cannot use sig-proxy without --attach")
}
- runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.Shutdown(false)
- if c.Latest {
- lastCtr, err := runtime.GetLatestContainer()
- if err != nil {
- return errors.Wrapf(err, "unable to get latest container")
- }
- args = append(args, lastCtr.ID())
- }
-
- ctx := getContext()
-
- var lastError error
- for _, container := range args {
- ctr, err := runtime.LookupContainer(container)
- if err != nil {
- if lastError != nil {
- fmt.Fprintln(os.Stderr, lastError)
- }
- lastError = errors.Wrapf(err, "unable to find container %s", container)
- continue
- }
-
- ctrState, err := ctr.State()
- if err != nil {
- return errors.Wrapf(err, "unable to get container state")
- }
-
- ctrRunning := ctrState == libpod.ContainerStateRunning
-
- if attach {
- inputStream := os.Stdin
- if !c.Interactive {
- inputStream = nil
- }
-
- // attach to the container and also start it not already running
- // If the container is in a pod, also set to recursively start dependencies
- err = adapter.StartAttachCtr(ctx, ctr, os.Stdout, os.Stderr, inputStream, c.DetachKeys, sigProxy, !ctrRunning, ctr.PodID() != "")
- if errors.Cause(err) == libpod.ErrDetach {
- // User manually detached
- // Exit cleanly immediately
- exitCode = 0
- return nil
- }
-
- if ctrRunning {
- return err
- }
-
- if err != nil {
- return errors.Wrapf(err, "unable to start container %s", ctr.ID())
- }
-
- if ecode, err := ctr.Wait(); err != nil {
- if errors.Cause(err) == libpod.ErrNoSuchCtr {
- // The container may have been removed
- // Go looking for an exit file
- rtc, err := runtime.GetConfig()
- if err != nil {
- return err
- }
- ctrExitCode, err := adapter.ReadExitFile(rtc.TmpDir, ctr.ID())
- if err != nil {
- logrus.Errorf("Cannot get exit code: %v", err)
- exitCode = 127
- } else {
- exitCode = ctrExitCode
- }
- }
- } else {
- exitCode = int(ecode)
- }
-
- return nil
- }
- if ctrRunning {
- fmt.Println(ctr.ID())
- continue
- }
- // Handle non-attach start
- // If the container is in a pod, also set to recursively start dependencies
- if err := ctr.Start(ctx, ctr.PodID() != ""); err != nil {
- if lastError != nil {
- fmt.Fprintln(os.Stderr, lastError)
- }
- lastError = errors.Wrapf(err, "unable to start container %q", container)
- continue
- }
- fmt.Println(container)
- }
-
- return lastError
+ exitCode, err = runtime.Start(getContext(), c, sigProxy)
+ return err
}