From 817cbb65e621b90a8fddf5190a6426206e3e4bbd Mon Sep 17 00:00:00 2001 From: Dirk Klimpel <5740567+dklimpel@users.noreply.github.com> Date: Thu, 21 Nov 2024 05:38:35 +0100 Subject: [PATCH] fix(dgoss): edgecase where no log is written (#997) * fix(dgoss): edgecase borderline case where no log is written * add force stop * refactor wait for logs --- extras/dgoss/dgoss | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/extras/dgoss/dgoss b/extras/dgoss/dgoss index 498c6ebb..f81e745a 100755 --- a/extras/dgoss/dgoss +++ b/extras/dgoss/dgoss @@ -19,12 +19,20 @@ error() { cleanup() { set +e + # There is a chance that the log will not be written completely. + # Exit the container and retrieve the last line of logs to ensure + # that all logs have been read. + info "Stopping container" + $CONTAINER_RUNTIME stop --time 1 "$id" > /dev/null 2>&1 + $CONTAINER_RUNTIME logs --tail 1 "$id" > /dev/null 2>&1 + { kill "$log_pid" && wait "$log_pid"; } 2> /dev/null if [ -n "$CONTAINER_LOG_OUTPUT" ]; then + info "Copying log" cp "$tmp_dir/docker_output.log" "$CONTAINER_LOG_OUTPUT" fi [ "$DEBUG" ] || rm -rf "$tmp_dir" - if [[ $id ]];then + if [[ $id ]]; then info "Deleting container" $CONTAINER_RUNTIME rm -vf "$id" > /dev/null fi