summaryrefslogtreecommitdiff
path: root/libpod/sql_state.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2017-11-21 13:44:22 -0500
committerAtomic Bot <atomic-devel@projectatomic.io>2017-11-21 20:09:09 +0000
commit8e76ebcf6e8925d5fa6a8c9ab517d665b44c7b63 (patch)
treecd9c15e37a00927ccd8c31b3cde40f46fe82b736 /libpod/sql_state.go
parent7b736e333315e6f533b9677712a0c2e037cc293b (diff)
downloadpodman-8e76ebcf6e8925d5fa6a8c9ab517d665b44c7b63.tar.gz
podman-8e76ebcf6e8925d5fa6a8c9ab517d665b44c7b63.tar.bz2
podman-8e76ebcf6e8925d5fa6a8c9ab517d665b44c7b63.zip
Add ability to update container status from runc
Wire this in to all state-bound container operations to ensure syncronization of container state. Also exposes PID of running containers via API. Signed-off-by: Matthew Heon <matthew.heon@gmail.com> Closes: #56 Approved by: rhatdan
Diffstat (limited to 'libpod/sql_state.go')
-rw-r--r--libpod/sql_state.go36
1 files changed, 28 insertions, 8 deletions
diff --git a/libpod/sql_state.go b/libpod/sql_state.go
index 466ad66a5..893223914 100644
--- a/libpod/sql_state.go
+++ b/libpod/sql_state.go
@@ -103,7 +103,9 @@ func (s *SQLState) Container(id string) (*Container, error) {
containerState.MountPoint,
containerState.StartedTime,
containerState.FinishedTime,
- containerState.ExitCode
+ containerState.ExitCode,
+ containerState.OomKilled,
+ containerState.Pid
FROM containers
INNER JOIN
containerState ON containers.Id = containerState.Id
@@ -136,7 +138,9 @@ func (s *SQLState) LookupContainer(idOrName string) (*Container, error) {
containerState.MountPoint,
containerState.StartedTime,
containerState.FinishedTime,
- containerState.ExitCode
+ containerState.ExitCode,
+ containerState.OomKilled,
+ containerState.Pid
FROM containers
INNER JOIN
containerState ON containers.Id = containerState.Id
@@ -220,7 +224,7 @@ func (s *SQLState) AddContainer(ctr *Container) (err error) {
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
);`
addCtrState = `INSERT INTO containerState VALUES (
- ?, ?, ?, ?, ?, ?, ?, ?
+ ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
);`
)
@@ -278,7 +282,9 @@ func (s *SQLState) AddContainer(ctr *Container) (err error) {
ctr.state.Mountpoint,
timeToSQL(ctr.state.StartedTime),
timeToSQL(ctr.state.FinishedTime),
- ctr.state.ExitCode)
+ ctr.state.ExitCode,
+ boolToSQL(ctr.state.OOMKilled),
+ ctr.state.PID)
if err != nil {
return errors.Wrapf(err, "error adding container %s state to database", ctr.ID())
}
@@ -315,7 +321,9 @@ func (s *SQLState) UpdateContainer(ctr *Container) error {
Mountpoint,
StartedTime,
FinishedTime,
- ExitCode
+ ExitCode,
+ OomKilled,
+ Pid
FROM containerState WHERE ID=?;`
var (
@@ -326,6 +334,8 @@ func (s *SQLState) UpdateContainer(ctr *Container) error {
startedTimeString string
finishedTimeString string
exitCode int32
+ oomKilled int
+ pid int
)
if !s.valid {
@@ -344,7 +354,9 @@ func (s *SQLState) UpdateContainer(ctr *Container) error {
&mountpoint,
&startedTimeString,
&finishedTimeString,
- &exitCode)
+ &exitCode,
+ &oomKilled,
+ &pid)
if err != nil {
// The container may not exist in the database
if err == sql.ErrNoRows {
@@ -364,6 +376,8 @@ func (s *SQLState) UpdateContainer(ctr *Container) error {
newState.RunDir = runDir
newState.Mountpoint = mountpoint
newState.ExitCode = exitCode
+ newState.OOMKilled = boolFromSQL(oomKilled)
+ newState.PID = pid
if newState.Mountpoint != "" {
newState.Mounted = true
@@ -396,7 +410,9 @@ func (s *SQLState) SaveContainer(ctr *Container) error {
Mountpoint=?,
StartedTime=?,
FinishedTime=?,
- ExitCode=?
+ ExitCode=?,
+ OomKilled=?,
+ Pid=?
WHERE Id=?;`
s.lock.Lock()
@@ -431,6 +447,8 @@ func (s *SQLState) SaveContainer(ctr *Container) error {
timeToSQL(ctr.state.StartedTime),
timeToSQL(ctr.state.FinishedTime),
ctr.state.ExitCode,
+ boolToSQL(ctr.state.OOMKilled),
+ ctr.state.PID,
ctr.ID())
if err != nil {
return errors.Wrapf(err, "error updating container %s state in database", ctr.ID())
@@ -521,7 +539,9 @@ func (s *SQLState) AllContainers() ([]*Container, error) {
containerState.MountPoint,
containerState.StartedTime,
containerState.FinishedTime,
- containerState.ExitCode
+ containerState.ExitCode,
+ containerState.OomKilled,
+ containerState.Pid
FROM containers
INNER JOIN
containerState ON containers.Id = containerState.Id;`