Skip to content
Merged
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
2 changes: 0 additions & 2 deletions cmd/podman/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ func getMainCommands() []*cobra.Command {
_refreshCommand,
_restartCommand,
_searchCommand,
_startCommand,
_statsCommand,
_topCommand,
_unpauseCommand,
Expand Down Expand Up @@ -57,7 +56,6 @@ func getContainerSubCommands() []*cobra.Command {
_restartCommand,
_restoreCommand,
_runlabelCommand,
_startCommand,
_statsCommand,
_stopCommand,
_topCommand,
Expand Down
1 change: 1 addition & 0 deletions cmd/podman/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ var (
_logsCommand,
_runCommand,
_rmCommand,
_startCommand,
_waitCommand,
}
)
Expand Down
1 change: 1 addition & 0 deletions cmd/podman/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var mainCommands = []*cobra.Command{
_versionCommand,
_waitCommand,
imageCommand.Command,
_startCommand,
systemCommand.Command,
}

Expand Down
14 changes: 11 additions & 3 deletions cmd/podman/shared/intermediate_varlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ package shared

import (
"fmt"

"github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/varlink"
"github.com/containers/libpod/pkg/rootless"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -318,6 +320,12 @@ func VarlinkCreateToGeneric(opts iopodman.Create) GenericCLIResults {
// We do not get a default network over varlink. Unlike the other default values for some cli
// elements, it seems it gets set to the default anyway.

var memSwapDefault int64 = -1
netModeDefault := "bridge"
if rootless.IsRootless() {
netModeDefault = "slirp4netns"
}

m := make(map[string]GenericCLIResult)
m["add-host"] = stringSliceFromVarlink(opts.AddHost, "add-host", nil)
m["annotation"] = stringSliceFromVarlink(opts.Annotation, "annotation", nil)
Expand Down Expand Up @@ -374,10 +382,10 @@ func VarlinkCreateToGeneric(opts iopodman.Create) GenericCLIResults {
m["memory"] = stringFromVarlink(opts.Memory, "memory", nil)
m["memory-reservation"] = stringFromVarlink(opts.MemoryReservation, "memory-reservation", nil)
m["memory-swap"] = stringFromVarlink(opts.MemorySwap, "memory-swap", nil)
m["memory-swappiness"] = int64FromVarlink(opts.MemorySwappiness, "memory-swappiness", nil)
m["memory-swappiness"] = int64FromVarlink(opts.MemorySwappiness, "memory-swappiness", &memSwapDefault)
m["name"] = stringFromVarlink(opts.Name, "name", nil)
m["net"] = stringFromVarlink(opts.Net, "net", nil)
m["network"] = stringFromVarlink(opts.Network, "network", nil)
m["net"] = stringFromVarlink(opts.Net, "net", &netModeDefault)
m["network"] = stringFromVarlink(opts.Network, "network", &netModeDefault)
m["no-hosts"] = boolFromVarlink(opts.NoHosts, "no-hosts", false)
m["oom-kill-disable"] = boolFromVarlink(opts.OomKillDisable, "oon-kill-disable", false)
m["oom-score-adj"] = intFromVarlink(opts.OomScoreAdj, "oom-score-adj", nil)
Expand Down
104 changes: 5 additions & 99 deletions cmd/podman/start.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand Down Expand Up @@ -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()
}
Expand All @@ -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
}
97 changes: 97 additions & 0 deletions pkg/adapter/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,100 @@ func (r *LocalRuntime) Restore(c *cliconfig.RestoreValues, options libpod.Contai
}
return lastError
}

// Start will start a container
func (r *LocalRuntime) Start(ctx context.Context, c *cliconfig.StartValues, sigProxy bool) (int, error) {
var (
exitCode = 125
lastError error
)

args := c.InputArgs
if c.Latest {
lastCtr, err := r.GetLatestContainer()
if err != nil {
return 0, errors.Wrapf(err, "unable to get latest container")
}
args = append(args, lastCtr.ID())
}

for _, container := range args {
ctr, err := r.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 exitCode, errors.Wrapf(err, "unable to get container state")
}

ctrRunning := ctrState == libpod.ContainerStateRunning

if c.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 = StartAttachCtr(ctx, ctr.Container, 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 exitCode, nil
}

if ctrRunning {
return 0, err
}

if err != nil {
return exitCode, 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 := r.GetConfig()
if err != nil {
return 0, err
}
ctrExitCode, err := 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 exitCode, 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 exitCode, lastError
}
Loading