From 5ce403cec251926d6887a827eaa7861b460707e0 Mon Sep 17 00:00:00 2001 From: Copilot <223556219+Copilot@users.noreply.github.com> Date: Sun, 15 Nov 2026 14:28:07 +0100 Subject: [PATCH] fix: Send data handler output to container logs Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- data_handler/Containerfile | 2 +- data_handler/utils/entrypoint.sh | 5 +++-- data_handler/utils/run_update_camera.sh | 12 ++++++++++++ docker-compose.yml | 4 ++-- 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 data_handler/utils/run_update_camera.sh diff --git a/data_handler/Containerfile b/data_handler/Containerfile index 4c08fa6..0da9985 100644 --- a/data_handler/Containerfile +++ b/data_handler/Containerfile @@ -5,4 +5,4 @@ COPY ./data_init/*.sql /opt/init/init.sql ENTRYPOINT ["/opt/entrypoint.sh"] -CMD ["/bin/sh", "-c", "/usr/sbin/dcrond -f -d 5 > /var/log/dcrond.log 2>&1"] \ No newline at end of file +CMD ["/usr/sbin/dcrond", "-f", "-d", "5"] \ No newline at end of file diff --git a/data_handler/utils/entrypoint.sh b/data_handler/utils/entrypoint.sh index 9e726e8..1933ef1 100755 --- a/data_handler/utils/entrypoint.sh +++ b/data_handler/utils/entrypoint.sh @@ -1,6 +1,7 @@ #!/bin/sh set -e +printf 'ok\n' > /run/update_camera.status #################################################################################################### ### Crontab settings @@ -8,7 +9,7 @@ set -e cat<> /var/log/update_camera_$(date +\%Y\%m\%d\%H\%M\%S).log 2>&1 +*/15 * * * * sh /opt/run_update_camera.sh EOF #################################################################################################### @@ -24,7 +25,7 @@ echo "Prescripts done" #################################################################################################### echo "Running update once initially..." -sh /opt/update_camera.sh >> /var/log/update_camera_$(date +\%Y\%m\%d\%H\%M\%S).log 2>&1 +sh /opt/run_update_camera.sh echo "Initial update done" #################################################################################################### diff --git a/data_handler/utils/run_update_camera.sh b/data_handler/utils/run_update_camera.sh new file mode 100644 index 0000000..431d3e1 --- /dev/null +++ b/data_handler/utils/run_update_camera.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +status_file=/run/update_camera.status +status_file_tmp="${status_file}.$$" + +if sh /opt/update_camera.sh 2>&1 | tee /proc/1/fd/1 | grep -i error >/dev/null; then + printf 'error\n' > "$status_file_tmp" +else + printf 'ok\n' > "$status_file_tmp" +fi + +mv "$status_file_tmp" "$status_file" diff --git a/docker-compose.yml b/docker-compose.yml index 290227d..ff2f3f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -58,9 +58,9 @@ services: db: condition: service_healthy restart: true - # if the latest `update_camera_*.log` contains "error", fail the healthcheck + # if the latest update output contains "error", fail the healthcheck healthcheck: - test: ["CMD", "sh", "-c", "ls /var/log | grep '^update_camera_' | xargs -I {} sh -c 'grep -q error /var/log/{} || exit 0; exit 1'"] + test: ["CMD", "sh", "-c", "test \"$(cat /run/update_camera.status)\" = ok"] interval: 10s timeout: 5s start_period: 30s