From 8587caa605118be3bc9cc06046c5a4bfcc3f7f67 Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Tue, 5 Nov 2024 08:53:42 +0100 Subject: [PATCH 1/3] fix(dgoss): edgecase borderline case where no log is written --- extras/dgoss/dgoss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/extras/dgoss/dgoss b/extras/dgoss/dgoss index 962d429c9..843eed2ac 100755 --- a/extras/dgoss/dgoss +++ b/extras/dgoss/dgoss @@ -20,6 +20,8 @@ cleanup() { set +e { kill "$log_pid" && wait "$log_pid"; } 2> /dev/null if [ -n "$CONTAINER_LOG_OUTPUT" ]; then + info "Stopping container and copy log" + $CONTAINER_RUNTIME stop "$id" > /dev/null cp "$tmp_dir/docker_output.log" "$CONTAINER_LOG_OUTPUT" fi rm -rf "$tmp_dir" @@ -66,6 +68,8 @@ run(){ esac $CONTAINER_RUNTIME logs -f "$id" > "$tmp_dir/docker_output.log" 2>&1 & + # There is a chance that the log will not be written, an empty line is added for mitigation. + echo "" >> "$tmp_dir/docker_output.log" 2>&1 & log_pid=$! info "Container ID: ${id:0:8}" } From 602e691b1739f01b0e8f61132fbb9e9bb136fcd4 Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Tue, 5 Nov 2024 09:39:10 +0100 Subject: [PATCH 2/3] add force stop --- extras/dgoss/dgoss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extras/dgoss/dgoss b/extras/dgoss/dgoss index 843eed2ac..e6b72b459 100755 --- a/extras/dgoss/dgoss +++ b/extras/dgoss/dgoss @@ -21,7 +21,7 @@ cleanup() { { kill "$log_pid" && wait "$log_pid"; } 2> /dev/null if [ -n "$CONTAINER_LOG_OUTPUT" ]; then info "Stopping container and copy log" - $CONTAINER_RUNTIME stop "$id" > /dev/null + $CONTAINER_RUNTIME stop -t 1 "$id" > /dev/null cp "$tmp_dir/docker_output.log" "$CONTAINER_LOG_OUTPUT" fi rm -rf "$tmp_dir" From f929682d557c485514e239836d470ee5f8e3ea95 Mon Sep 17 00:00:00 2001 From: dklimpel <5740567+dklimpel@users.noreply.github.com> Date: Sat, 16 Nov 2024 17:30:13 +0100 Subject: [PATCH 3/3] refactor wait for logs --- extras/dgoss/dgoss | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/extras/dgoss/dgoss b/extras/dgoss/dgoss index e6b72b459..94fdeec6f 100755 --- a/extras/dgoss/dgoss +++ b/extras/dgoss/dgoss @@ -18,14 +18,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 "Stopping container and copy log" - $CONTAINER_RUNTIME stop -t 1 "$id" > /dev/null + info "Copying log" cp "$tmp_dir/docker_output.log" "$CONTAINER_LOG_OUTPUT" fi rm -rf "$tmp_dir" - if [[ $id ]];then + if [[ $id ]]; then info "Deleting container" $CONTAINER_RUNTIME rm -vf "$id" > /dev/null fi @@ -68,8 +74,6 @@ run(){ esac $CONTAINER_RUNTIME logs -f "$id" > "$tmp_dir/docker_output.log" 2>&1 & - # There is a chance that the log will not be written, an empty line is added for mitigation. - echo "" >> "$tmp_dir/docker_output.log" 2>&1 & log_pid=$! info "Container ID: ${id:0:8}" }