Skip to main content

Module docker_post_mortem

Module docker_post_mortem 

Source
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 from exit_reason) decodes 128 + n once, 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§

ContainerPostMortem
Facts read out of a container’s State after it stopped.

Constants§

DOCKER_RUNNING_INSPECT_FORMAT
docker inspect -f template answering “is the container still running?”.
DOCKER_STATE_INSPECT_FORMAT
docker inspect -f template collecting every post-mortem fact at once.
DOCKER_ZERO_TIME
Docker’s zero value for a timestamp that was never set. State.FinishedAt carries it for every container that has not finished, and State.StartedAt for every container that never started. It must never reach a record as an endTime: a year-1 timestamp is worse than an honest null.
LOG_CAPTURE_STOPPED_NOTE
Written into the log when docker logs -f returned while the container was still running (issue #174).
NO_ERROR
Placeholder for State.Error when 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 + n into 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.