mirror of
https://github.com/containers/podman.git
synced 2025-12-11 01:11:30 +08:00
Add 'podman restart' command
Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #503 Approved by: rhatdan
This commit is contained in:
@@ -56,6 +56,7 @@ func main() {
|
|||||||
portCommand,
|
portCommand,
|
||||||
pullCommand,
|
pullCommand,
|
||||||
pushCommand,
|
pushCommand,
|
||||||
|
restartCommand,
|
||||||
rmCommand,
|
rmCommand,
|
||||||
rmiCommand,
|
rmiCommand,
|
||||||
runCommand,
|
runCommand,
|
||||||
|
|||||||
110
cmd/podman/restart.go
Normal file
110
cmd/podman/restart.go
Normal file
@@ -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
|
||||||
|
}
|
||||||
@@ -1312,6 +1312,16 @@ _podman_run() {
|
|||||||
_podman_container_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() {
|
_podman_rm() {
|
||||||
local boolean_options="
|
local boolean_options="
|
||||||
--all
|
--all
|
||||||
|
|||||||
45
docs/podman-restart.1.md
Normal file
45
docs/podman-restart.1.md
Normal file
@@ -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>
|
||||||
62
transfer.md
62
transfer.md
@@ -38,36 +38,37 @@ There are other equivalents for these tools
|
|||||||
|
|
||||||
| Existing Step | PODMAN (and friends) |
|
| Existing Step | PODMAN (and friends) |
|
||||||
| :--- | :--- |
|
| :--- | :--- |
|
||||||
| `docker attach` | [`podman exec`](./docs/podman-attach.1.md)|
|
| `docker attach` | [`podman exec`](./docs/podman-attach.1.md) |
|
||||||
| `docker build` | [`podman build`](./docs/podman-build.1.md) |
|
| `docker build` | [`podman build`](./docs/podman-build.1.md) |
|
||||||
| `docker commit` | [`podman commit`](./docs/podman-commit.1.md)|
|
| `docker commit` | [`podman commit`](./docs/podman-commit.1.md) |
|
||||||
| `docker cp` | [`podman mount`](./docs/podman-cp.1.md) **** |
|
| `docker cp` | [`podman mount`](./docs/podman-cp.1.md) **** |
|
||||||
| `docker create` | [`podman create`](./docs/podman-create.1.md) |
|
| `docker create` | [`podman create`](./docs/podman-create.1.md) |
|
||||||
| `docker diff` | [`podman diff`](./docs/podman-diff.1.md) |
|
| `docker diff` | [`podman diff`](./docs/podman-diff.1.md) |
|
||||||
| `docker export` | [`podman export`](./docs/podman-export.1.md) |
|
| `docker export` | [`podman export`](./docs/podman-export.1.md) |
|
||||||
| `docker history`| [`podman history`](./docs/podman-history.1.md)|
|
| `docker history` | [`podman history`](./docs/podman-history.1.md) |
|
||||||
| `docker images` | [`podman images`](./docs/podman-images.1.md) |
|
| `docker images` | [`podman images`](./docs/podman-images.1.md) |
|
||||||
| `docker import` | [`podman import`](./docs/podman-import.1.md) |
|
| `docker import` | [`podman import`](./docs/podman-import.1.md) |
|
||||||
| `docker kill` | [`podman kill`](./docs/podman-kill.1.md) |
|
| `docker kill` | [`podman kill`](./docs/podman-kill.1.md) |
|
||||||
| `docker load` | [`podman load`](./docs/podman-load.1.md) |
|
| `docker load` | [`podman load`](./docs/podman-load.1.md) |
|
||||||
| `docker login` | [`podman login`](./docs/podman-login.1.md) |
|
| `docker login` | [`podman login`](./docs/podman-login.1.md) |
|
||||||
| `docker logout` | [`podman logout`](./docs/podman-logout.1.md) |
|
| `docker logout` | [`podman logout`](./docs/podman-logout.1.md) |
|
||||||
| `docker pause` | [`podman pause`](./docs/podman-pause.1.md) |
|
| `docker pause` | [`podman pause`](./docs/podman-pause.1.md) |
|
||||||
| `docker ps` | [`podman ps`](./docs/podman-ps.1.md) |
|
| `docker ps` | [`podman ps`](./docs/podman-ps.1.md) |
|
||||||
| `docker pull` | [`podman pull`](./docs/podman-pull.1.md) |
|
| `docker pull` | [`podman pull`](./docs/podman-pull.1.md) |
|
||||||
| `docker push` | [`podman push`](./docs/podman-push.1.md) |
|
| `docker push` | [`podman push`](./docs/podman-push.1.md) |
|
||||||
| `docker rm` | [`podman rm`](./docs/podman-rm.1.md) |
|
| `docker restart` | [`podman restart`](./docs/podman-restart.1.md)] |
|
||||||
| `docker rmi` | [`podman rmi`](./docs/podman-rmi.1.md) |
|
| `docker rm` | [`podman rm`](./docs/podman-rm.1.md) |
|
||||||
| `docker run` | [`podman run`](./docs/podman-run.1.md) |
|
| `docker rmi` | [`podman rmi`](./docs/podman-rmi.1.md) |
|
||||||
| `docker save` | [`podman save`](./docs/podman-save.1.md) |
|
| `docker run` | [`podman run`](./docs/podman-run.1.md) |
|
||||||
| `docker search` | [`podman search`](./docs/podman-search.1.md) |
|
| `docker save` | [`podman save`](./docs/podman-save.1.md) |
|
||||||
| `docker start` | [`podman start`](./docs/podman-start.1.md) |
|
| `docker search` | [`podman search`](./docs/podman-search.1.md) |
|
||||||
| `docker stop` | [`podman stop`](./docs/podman-stop.1.md) |
|
| `docker start` | [`podman start`](./docs/podman-start.1.md) |
|
||||||
| `docker tag` | [`podman tag`](./docs/podman-tag.1.md) |
|
| `docker stop` | [`podman stop`](./docs/podman-stop.1.md) |
|
||||||
| `docker top` | [`podman top`](./docs/podman-top.1.md) |
|
| `docker tag` | [`podman tag`](./docs/podman-tag.1.md) |
|
||||||
| `docker unpause`| [`podman unpause`](./docs/podman-unpause.1.md)|
|
| `docker top` | [`podman top`](./docs/podman-top.1.md) |
|
||||||
| `docker version`| [`podman version`](./docs/podman-version.1.md)|
|
| `docker unpause` | [`podman unpause`](./docs/podman-unpause.1.md) |
|
||||||
| `docker wait` | [`podman wait`](./docs/podman-wait.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.
|
**** 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 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 port` ||
|
||||||
| `docker rename` | podman does not support rename, you need to use `podman rm` and `podman create` to rename a container.|
|
| `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 secret` ||
|
||||||
| `docker service` ||
|
| `docker service` ||
|
||||||
| `docker stack` ||
|
| `docker stack` ||
|
||||||
|
|||||||
Reference in New Issue
Block a user