Expand description
Container post-mortem facts (issues #170, #171).
When a detached container dies the only thing start used to write into the
log was Reason: exitCode=137 oomKilled=false — the two facts that, together,
say the least. 137 is 128 + 9, i.e. SIGKILL, and oomKilled=false rules
out the cgroup OOM killer, so the container was killed from the outside
(docker kill, a docker stop escalation, systemd, the CI runner). None of
that was said out loud, and the three fields that would have shown when it
happened — State.StartedAt, State.FinishedAt, State.Error — were never
read at all, even though the watcher was already one docker inspect away
from them.
This module owns those facts in one place:
describe_exit_code()(re-exported fromexit_reason) decodes128 + nonce, for the watcher (completion time, written into the log) and for--status(query time, in memory), so the two can never disagree;- the
build_*_snippet()helpers generate the POSIX shell the detached watcher runs, including the signal table, so the shell and the runtime share a single source of truth; format_container_post_mortem()renders the same block for callers that already hold the facts in memory (the attached docker path).
Modules§
- shell_
vars - Shell variables the completion watcher fills in and the snippets consume.
Structs§
- Container
Post Mortem - Facts read out of a container’s
Stateafter it stopped.
Constants§
- DOCKER_
RUNNING_ INSPECT_ FORMAT docker inspect -ftemplate answering “is the container still running?”.- DOCKER_
STATE_ INSPECT_ FORMAT docker inspect -ftemplate collecting every post-mortem fact at once.- DOCKER_
ZERO_ TIME - Docker’s zero value for a timestamp that was never set.
State.FinishedAtcarries it for every container that has not finished, andState.StartedAtfor every container that never started. It must never reach a record as anendTime: a year-1 timestamp is worse than an honestnull. - LOG_
CAPTURE_ STOPPED_ NOTE - Written into the log when
docker logs -freturned while the container was still running (issue #174). - NO_
ERROR - Placeholder for
State.Errorwhen docker reported no error at all. - POST_
MORTEM_ HEADER - Header line of the post-mortem block appended to a kept container’s log.
- STILL_
RUNNING_ NOTE - Written into the log when the watcher gave up while the container was still
running. No footer follows: an
Exit Code:line would be a fabrication. - UNKNOWN
- Placeholder written instead of a fact that could not be observed.
Functions§
- build_
docker_ post_ mortem_ snippet - Shell fragment appending the post-mortem block for a kept container.
- build_
docker_ removal_ note_ snippet - Shell fragment appending the one-line note for a removed container.
- build_
docker_ running_ condition - Shell condition that holds while the container is running.
- build_
docker_ state_ snippet - Shell fragment reading the container’s terminal state.
- build_
docker_ still_ running_ note_ snippet - Shell fragment appending the note for a container the watcher lost while it was still running (issue #174).
- build_
docker_ wait_ for_ exit_ snippet - Shell fragment blocking until the container has really exited.
- build_
lifetime_ snippet - Shell fragment computing how long the container was alive.
- build_
signal_ decode_ snippet - Shell fragment decoding
128 + ninto a signal name. - format_
container_ post_ mortem - Render the post-mortem block for facts already held in memory.
- format_
container_ removal_ note - Render the single line written when a container is removed, so a successful run keeps its log terse while still carrying the same facts (issue #171.3).
- format_
lifetime - Format the time a container was alive, e.g.
5.798s. - normalize_
docker_ timestamp - Normalize a timestamp reported by
docker inspect.