From a3d13fb286c39a2d9195b70e4265e5ac0deb6fd3 Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Wed, 20 Nov 2019 14:10:48 +0100 Subject: podman {pod,} rm/stop: add --ignore flag Add an --ignore flag to podman rm and stop. When specified, Podman will ignore "no such {container,pod}" errors that occur when a specified container/pod is not present in the store (anymore). The motivation behind adding this flag is to write more robust systemd services using Podman. A user might have manually decided to remove a container/pod which would lead to a failure during the `ExecStop` directive of a systemd service referencing that container/pod. Signed-off-by: Valentin Rothberg --- cmd/podman/rm.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'cmd/podman/rm.go') diff --git a/cmd/podman/rm.go b/cmd/podman/rm.go index b3bc8e1b9..e69565e95 100644 --- a/cmd/podman/rm.go +++ b/cmd/podman/rm.go @@ -40,14 +40,16 @@ func init() { rmCommand.SetUsageTemplate(UsageTemplate()) flags := rmCommand.Flags() flags.BoolVarP(&rmCommand.All, "all", "a", false, "Remove all containers") + flags.BoolVarP(&rmCommand.Ignore, "ignore", "i", false, "Ignore errors when a specified container is missing") flags.BoolVarP(&rmCommand.Force, "force", "f", false, "Force removal of a running or unusable container. The default is false") flags.BoolVarP(&rmCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of") flags.BoolVar(&rmCommand.Storage, "storage", false, "Remove container from storage library") flags.BoolVarP(&rmCommand.Volumes, "volumes", "v", false, "Remove anonymous volumes associated with the container") flags.StringArrayVarP(&rmCommand.CIDFiles, "cidfile", "", nil, "Read the container ID from the file") - markFlagHiddenForRemoteClient("storage", flags) - markFlagHiddenForRemoteClient("latest", flags) + markFlagHiddenForRemoteClient("ignore", flags) markFlagHiddenForRemoteClient("cidfile", flags) + markFlagHiddenForRemoteClient("latest", flags) + markFlagHiddenForRemoteClient("storage", flags) } // rmCmd removes one or more containers @@ -58,10 +60,10 @@ func rmCmd(c *cliconfig.RmValues) error { } defer runtime.DeferredShutdown(false) - // Storage conflicts with --all/--latest/--volumes + // Storage conflicts with --all/--latest/--volumes/--cidfile/--ignore if c.Storage { - if c.All || c.Latest || c.Volumes || c.CIDFiles != nil { - return errors.Errorf("--storage conflicts with --volumes, --all, --latest and --cidfile") + if c.All || c.Ignore || c.Latest || c.Volumes || c.CIDFiles != nil { + return errors.Errorf("--storage conflicts with --volumes, --all, --latest, --ignore and --cidfile") } } -- cgit v1.2.3-54-g00ecf