aboutsummaryrefslogtreecommitdiff
path: root/libpod/container.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-04-01 13:30:28 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-05-03 10:36:16 -0400
commit3fb52f4fbb04781e32f72888c9e509dea5d7b434 (patch)
tree01918e60491ce2ce0e9345a052acfee8546d9fa4 /libpod/container.go
parent0eaba2d56a48c68e1d08e287a1c9eb5405cc743a (diff)
downloadpodman-3fb52f4fbb04781e32f72888c9e509dea5d7b434.tar.gz
podman-3fb52f4fbb04781e32f72888c9e509dea5d7b434.tar.bz2
podman-3fb52f4fbb04781e32f72888c9e509dea5d7b434.zip
Add a StoppedByUser field to the DB
This field indicates that a container was explciitly stopped by an API call, and did not exit naturally. It's used when implementing restart policy for containers. Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/container.go')
-rw-r--r--libpod/container.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/libpod/container.go b/libpod/container.go
index 4bf9a1ba9..570110ca1 100644
--- a/libpod/container.go
+++ b/libpod/container.go
@@ -179,6 +179,9 @@ type ContainerState struct {
// This maps the path the file will be mounted to in the container to
// the path of the file on disk outside the container
BindMounts map[string]string `json:"bindMounts,omitempty"`
+ // StoppedByUser indicates whether the container was stopped by an
+ // explicit call to the Stop() API.
+ StoppedByUser bool
// ExtensionStageHooks holds hooks which will be executed by libpod
// and not delegated to the OCI runtime.
@@ -1003,6 +1006,21 @@ func (c *Container) BindMounts() (map[string]string, error) {
return newMap, nil
}
+// StoppedByUser returns whether the container was last stopped by an explicit
+// call to the Stop() API, or whether it exited naturally.
+func (c *Container) StoppedByUser() (bool, error) {
+ if !c.batched {
+ c.lock.Lock()
+ defer c.lock.Unlock()
+
+ if err := c.syncContainer(); err != nil {
+ return false, err
+ }
+ }
+
+ return c.state.StoppedByUser, nil
+}
+
// Misc Accessors
// Most will require locking