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
This commit is contained in:
Matthew Heon
2017-11-21 13:44:22 -05:00
committed by Atomic Bot
parent 7b736e3333
commit 8e76ebcf6e
6 changed files with 197 additions and 60 deletions

View File

@ -61,7 +61,10 @@ func prepareDB(db *sql.DB) (err error) {
StartedTime TEXT NUT NULL,
FinishedTime TEXT NOT NULL,
ExitCode INTEGER NOT NULL,
OomKilled INTEGER NOT NULL,
Pid INTEGER NOT NULL,
CHECK (State>0),
CHECK (OomKilled IN (0, 1)),
FOREIGN KEY (Id) REFERENCES containers(Id) DEFERRABLE INITIALLY DEFERRED
);
`
@ -149,6 +152,8 @@ func ctrFromScannable(row scannable, runtime *Runtime, specsDir string) (*Contai
startedTimeString string
finishedTimeString string
exitCode int32
oomKilled int
pid int
)
err := row.Scan(
@ -169,7 +174,9 @@ func ctrFromScannable(row scannable, runtime *Runtime, specsDir string) (*Contai
&mountpoint,
&startedTimeString,
&finishedTimeString,
&exitCode)
&exitCode,
&oomKilled,
&pid)
if err != nil {
if err == sql.ErrNoRows {
return nil, ErrNoSuchCtr
@ -197,6 +204,8 @@ func ctrFromScannable(row scannable, runtime *Runtime, specsDir string) (*Contai
ctr.state.RunDir = runDir
ctr.state.Mountpoint = mountpoint
ctr.state.ExitCode = exitCode
ctr.state.OOMKilled = boolFromSQL(oomKilled)
ctr.state.PID = pid
// TODO should we store this in the database separately instead?
if ctr.state.Mountpoint != "" {