summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-03-15 15:00:18 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-03-16 13:55:49 +0000
commit2724434369037938f5dceaf7bf8268d4d5ce1a68 (patch)
tree92254cdf40bfb937fe405eec2b51a9c18705cbb6
parent8840b92da603f9db5ba2590f4b0836ad580fbe56 (diff)
downloadpodman-2724434369037938f5dceaf7bf8268d4d5ce1a68.tar.gz
podman-2724434369037938f5dceaf7bf8268d4d5ce1a68.tar.bz2
podman-2724434369037938f5dceaf7bf8268d4d5ce1a68.zip
Add 'podman restart' command
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #503 Approved by: rhatdan
-rw-r--r--cmd/podman/main.go1
-rw-r--r--cmd/podman/restart.go110
-rw-r--r--completions/bash/podman10
-rw-r--r--docs/podman-restart.1.md45
-rw-r--r--transfer.md62
5 files changed, 197 insertions, 31 deletions
diff --git a/cmd/podman/main.go b/cmd/podman/main.go
index 4034be267..2a0ca30ee 100644
--- a/cmd/podman/main.go
+++ b/cmd/podman/main.go
@@ -56,6 +56,7 @@ func main() {
portCommand,
pullCommand,
pushCommand,
+ restartCommand,
rmCommand,
rmiCommand,
runCommand,
diff --git a/cmd/podman/restart.go b/cmd/podman/restart.go
new file mode 100644
index 000000000..f96959a27
--- /dev/null
+++ b/cmd/podman/restart.go
@@ -0,0 +1,110 @@
+package main
+
+import (
+ "fmt"
+ "os"
+
+ "github.com/pkg/errors"
+ "github.com/projectatomic/libpod/libpod"
+ "github.com/urfave/cli"
+)
+
+var (
+ restartFlags = []cli.Flag{
+ cli.UintFlag{
+ Name: "timeout, time, t",
+ Usage: "Seconds to wait for stop before killing the container",
+ Value: libpod.CtrRemoveTimeout,
+ },
+ LatestFlag,
+ }
+ restartDescription = `Restarts one or more running containers. The container ID or name can be used. A timeout before forcibly stopping can be set, but defaults to 10 seconds`
+
+ restartCommand = cli.Command{
+ Name: "restart",
+ Usage: "Restart one or more containers",
+ Description: restartDescription,
+ Flags: restartFlags,
+ Action: restartCmd,
+ ArgsUsage: "CONTAINER [CONTAINER ...]",
+ UseShortOptionHandling: true,
+ }
+)
+
+func restartCmd(c *cli.Context) error {
+ args := c.Args()
+ if len(args) < 1 && !c.Bool("latest") {
+ return errors.Wrapf(libpod.ErrInvalidArg, "you must provide at least one container name or ID")
+ }
+
+ if err := validateFlags(c, restartFlags); err != nil {
+ return err
+ }
+
+ runtime, err := getRuntime(c)
+ if err != nil {
+ return errors.Wrapf(err, "error creating libpod runtime")
+ }
+ defer runtime.Shutdown(false)
+
+ var lastError error
+
+ timeout := c.Uint("timeout")
+ useTimeout := c.IsSet("timeout")
+
+ // Handle --latest
+ if c.Bool("latest") {
+ lastCtr, err := runtime.GetLatestContainer()
+ if err != nil {
+ lastError = errors.Wrapf(err, "unable to get latest container")
+ } else {
+ lastError = restartCtr(timeout, useTimeout, lastCtr)
+ }
+ }
+
+ for _, id := range args {
+ ctr, err := runtime.LookupContainer(id)
+ if err != nil {
+ if lastError != nil {
+ fmt.Fprintln(os.Stderr, lastError)
+ }
+ lastError = errors.Wrapf(err, "unable to find container %s", id)
+ continue
+ }
+
+ if err := restartCtr(timeout, useTimeout, ctr); err != nil {
+ if lastError != nil {
+ fmt.Fprintln(os.Stderr, lastError)
+ }
+ lastError = errors.Wrapf(err, "error restarting container %s", ctr.ID())
+ }
+ }
+
+ return lastError
+}
+
+// Restart a single container
+func restartCtr(cliTimeout uint, useTimeout bool, ctr *libpod.Container) error {
+ timeout := ctr.StopTimeout()
+ if useTimeout {
+ timeout = cliTimeout
+ }
+
+ state, err := ctr.State()
+ if err != nil {
+ return err
+ }
+ if state == libpod.ContainerStateRunning {
+ if err := ctr.StopWithTimeout(timeout); err != nil {
+ return err
+ }
+ }
+
+ if err := ctr.Start(); err != nil {
+ return err
+ }
+
+ fmt.Printf("%s\n", ctr.ID())
+
+ return nil
+}
diff --git a/completions/bash/podman b/completions/bash/podman
index d4334d68b..5df1eaa36 100644
--- a/completions/bash/podman
+++ b/completions/bash/podman
@@ -1312,6 +1312,16 @@ _podman_run() {
_podman_container_run
}
+_podman_restart() {
+ local options_with_args="
+ --timeout -t
+ "
+ local boolean_options="
+ --latest
+ -l"
+ _complete_ "$options_with_args" "$boolean_options"
+}
+
_podman_rm() {
local boolean_options="
--all
diff --git a/docs/podman-restart.1.md b/docs/podman-restart.1.md
new file mode 100644
index 000000000..0710793d7
--- /dev/null
+++ b/docs/podman-restart.1.md
@@ -0,0 +1,45 @@
+% podman(1) podman-restart - Restart a container
+% Matt Heon
+# podman-restart "1" "March 2017" "podman"
+
+## NAME
+podman restart - Restart a container
+
+## SYNOPSIS
+**podman attach [OPTIONS] CONTAINER [CONTAINER...]**
+
+## DESCRIPTION
+The restart command allows containers to be restarted using their ID or name.
+Containers will be stopped if they are running and then restarted.
+
+## OPTIONS
+**--timeout**
+Timeout to wait before forcibly stopping the container
+
+**--latest, -l**
+Instead of providing the container name or ID, use the last created container. If you use methods other than Podman
+to run containers such as CRI-O, the last started container could be from either of those methods.
+
+## EXAMPLES ##
+
+```
+podman restart -l
+ec588fc80b05e19d3006bf2e8aa325f0a2e2ff1f609b7afb39176ca8e3e13467
+```
+
+```
+podman restart ff6cf1
+ff6cf1e5e77e6dba1efc7f3fcdb20e8b89ad8947bc0518be1fcb2c78681f226f
+```
+
+```
+podman restart --timeout 4 test1 test2
+c3bb026838c30e5097f079fa365c9a4769d52e1017588278fa00d5c68ebc1502
+17e13a63081a995136f907024bcfe50ff532917988a152da229db9d894c5a9ec
+```
+
+## SEE ALSO
+podman(1), podman-run(1), podman-start(1), podman-create(1)
+
+## HISTORY
+March 2018, Originally compiled by Matt Heon <mheon@redhat.com>
diff --git a/transfer.md b/transfer.md
index 53d6c472c..2748004ec 100644
--- a/transfer.md
+++ b/transfer.md
@@ -38,36 +38,37 @@ There are other equivalents for these tools
| Existing Step | PODMAN (and friends) |
| :--- | :--- |
-| `docker attach` | [`podman exec`](./docs/podman-attach.1.md)|
-| `docker build` | [`podman build`](./docs/podman-build.1.md) |
-| `docker commit` | [`podman commit`](./docs/podman-commit.1.md)|
-| `docker cp` | [`podman mount`](./docs/podman-cp.1.md) **** |
-| `docker create` | [`podman create`](./docs/podman-create.1.md) |
-| `docker diff` | [`podman diff`](./docs/podman-diff.1.md) |
-| `docker export` | [`podman export`](./docs/podman-export.1.md) |
-| `docker history`| [`podman history`](./docs/podman-history.1.md)|
-| `docker images` | [`podman images`](./docs/podman-images.1.md) |
-| `docker import` | [`podman import`](./docs/podman-import.1.md) |
-| `docker kill` | [`podman kill`](./docs/podman-kill.1.md) |
-| `docker load` | [`podman load`](./docs/podman-load.1.md) |
-| `docker login` | [`podman login`](./docs/podman-login.1.md) |
-| `docker logout` | [`podman logout`](./docs/podman-logout.1.md) |
-| `docker pause` | [`podman pause`](./docs/podman-pause.1.md) |
-| `docker ps` | [`podman ps`](./docs/podman-ps.1.md) |
-| `docker pull` | [`podman pull`](./docs/podman-pull.1.md) |
-| `docker push` | [`podman push`](./docs/podman-push.1.md) |
-| `docker rm` | [`podman rm`](./docs/podman-rm.1.md) |
-| `docker rmi` | [`podman rmi`](./docs/podman-rmi.1.md) |
-| `docker run` | [`podman run`](./docs/podman-run.1.md) |
-| `docker save` | [`podman save`](./docs/podman-save.1.md) |
-| `docker search` | [`podman search`](./docs/podman-search.1.md) |
-| `docker start` | [`podman start`](./docs/podman-start.1.md) |
-| `docker stop` | [`podman stop`](./docs/podman-stop.1.md) |
-| `docker tag` | [`podman tag`](./docs/podman-tag.1.md) |
-| `docker top` | [`podman top`](./docs/podman-top.1.md) |
-| `docker unpause`| [`podman unpause`](./docs/podman-unpause.1.md)|
-| `docker version`| [`podman version`](./docs/podman-version.1.md)|
-| `docker wait` | [`podman wait`](./docs/podman-wait.1.md) |
+| `docker attach` | [`podman exec`](./docs/podman-attach.1.md) |
+| `docker build` | [`podman build`](./docs/podman-build.1.md) |
+| `docker commit` | [`podman commit`](./docs/podman-commit.1.md) |
+| `docker cp` | [`podman mount`](./docs/podman-cp.1.md) **** |
+| `docker create` | [`podman create`](./docs/podman-create.1.md) |
+| `docker diff` | [`podman diff`](./docs/podman-diff.1.md) |
+| `docker export` | [`podman export`](./docs/podman-export.1.md) |
+| `docker history` | [`podman history`](./docs/podman-history.1.md) |
+| `docker images` | [`podman images`](./docs/podman-images.1.md) |
+| `docker import` | [`podman import`](./docs/podman-import.1.md) |
+| `docker kill` | [`podman kill`](./docs/podman-kill.1.md) |
+| `docker load` | [`podman load`](./docs/podman-load.1.md) |
+| `docker login` | [`podman login`](./docs/podman-login.1.md) |
+| `docker logout` | [`podman logout`](./docs/podman-logout.1.md) |
+| `docker pause` | [`podman pause`](./docs/podman-pause.1.md) |
+| `docker ps` | [`podman ps`](./docs/podman-ps.1.md) |
+| `docker pull` | [`podman pull`](./docs/podman-pull.1.md) |
+| `docker push` | [`podman push`](./docs/podman-push.1.md) |
+| `docker restart` | [`podman restart`](./docs/podman-restart.1.md)] |
+| `docker rm` | [`podman rm`](./docs/podman-rm.1.md) |
+| `docker rmi` | [`podman rmi`](./docs/podman-rmi.1.md) |
+| `docker run` | [`podman run`](./docs/podman-run.1.md) |
+| `docker save` | [`podman save`](./docs/podman-save.1.md) |
+| `docker search` | [`podman search`](./docs/podman-search.1.md) |
+| `docker start` | [`podman start`](./docs/podman-start.1.md) |
+| `docker stop` | [`podman stop`](./docs/podman-stop.1.md) |
+| `docker tag` | [`podman tag`](./docs/podman-tag.1.md) |
+| `docker top` | [`podman top`](./docs/podman-top.1.md) |
+| `docker unpause` | [`podman unpause`](./docs/podman-unpause.1.md) |
+| `docker version` | [`podman version`](./docs/podman-version.1.md) |
+| `docker wait` | [`podman wait`](./docs/podman-wait.1.md) |
**** Use mount to take advantage of the entire linux tool chain rather then just cp. Read [`here`](./docs/podman-cp.1.md) for more information.
@@ -85,7 +86,6 @@ Those Docker commands currently do not have equivalents in `podman`:
| `docker plugin` |podman does not support plugins. We recommend you use alternative OCI Runtimes or OCI Runtime Hooks to alter behavior of podman.|
| `docker port` ||
| `docker rename` | podman does not support rename, you need to use `podman rm` and `podman create` to rename a container.|
-| `docker restart` | podman does not support restart. We recommend that you put your podman containers into a systemd unit file and use it for restarting applications.|
| `docker secret` ||
| `docker service` ||
| `docker stack` ||