diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2019-11-15 14:05:46 -0500 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2019-11-18 14:44:08 +0100 |
commit | 061bf77588c573668646fb07ded748c9bf375130 (patch) | |
tree | ab5a0374830213f887ce5aae4816d7bca567d2d9 /pkg/adapter/containers.go | |
parent | d7ed9fa188b502e155ddbf6b626cf8fbfc92bbb8 (diff) | |
download | podman-061bf77588c573668646fb07ded748c9bf375130.tar.gz podman-061bf77588c573668646fb07ded748c9bf375130.tar.bz2 podman-061bf77588c573668646fb07ded748c9bf375130.zip |
podman rm/stop --cidfile
Add a --cidfile flag to podman rm/stop to pass a container ID via a
file. Podman run already provides the functionaly to store the ID
in a specified file which we now complete with rm/stop. This allows
for a better life-cycle management in systemd services. Note that
--cdifile can be specified multiple times to rm/stop.
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg/adapter/containers.go')
-rw-r--r-- | pkg/adapter/containers.go | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/pkg/adapter/containers.go b/pkg/adapter/containers.go index 287bd8474..02da9ec8c 100644 --- a/pkg/adapter/containers.go +++ b/pkg/adapter/containers.go @@ -79,7 +79,17 @@ func (r *LocalRuntime) StopContainers(ctx context.Context, cli *cliconfig.StopVa } logrus.Debugf("Setting maximum stop workers to %d", maxWorkers) - ctrs, err := shortcuts.GetContainersByContext(cli.All, cli.Latest, cli.InputArgs, r.Runtime) + names := cli.InputArgs + for _, cidFile := range cli.CIDFiles { + content, err := ioutil.ReadFile(cidFile) + if err != nil { + return nil, nil, errors.Wrap(err, "error reading CIDFile") + } + id := strings.Split(string(content), "\n")[0] + names = append(names, id) + } + + ctrs, err := shortcuts.GetContainersByContext(cli.All, cli.Latest, names, r.Runtime) if err != nil { return nil, nil, err } @@ -203,7 +213,17 @@ func (r *LocalRuntime) RemoveContainers(ctx context.Context, cli *cliconfig.RmVa return ok, failures, nil } - ctrs, err := shortcuts.GetContainersByContext(cli.All, cli.Latest, cli.InputArgs, r.Runtime) + names := cli.InputArgs + for _, cidFile := range cli.CIDFiles { + content, err := ioutil.ReadFile(cidFile) + if err != nil { + return nil, nil, errors.Wrap(err, "error reading CIDFile") + } + id := strings.Split(string(content), "\n")[0] + names = append(names, id) + } + + ctrs, err := shortcuts.GetContainersByContext(cli.All, cli.Latest, names, r.Runtime) if err != nil { // Failed to get containers. If force is specified, get the containers ID // and evict them |