From 9677eb37e13311367204b86e920a2f350534b90d Mon Sep 17 00:00:00 2001 From: Sergey Katsubo Date: Wed, 28 May 2025 20:13:04 +0300 Subject: [PATCH] feat(server): log failed healthchecks to server container stderr in verbose mode (#18709) * Log failed healthchecks to server container stderr in verbose mode * Formatting: indentation, semicolons * Readability: less escaping --- server/bin/immich-healthcheck | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/server/bin/immich-healthcheck b/server/bin/immich-healthcheck index 81528157e4a..e6bdd280500 100755 --- a/server/bin/immich-healthcheck +++ b/server/bin/immich-healthcheck @@ -1,8 +1,14 @@ #!/usr/bin/env bash +log_container_verbose() { + if [[ $IMMICH_LOG_LEVEL == verbose ]]; then + echo "$1" > /proc/1/fd/2 + fi +} + if [[ ( $IMMICH_WORKERS_INCLUDE != '' && $IMMICH_WORKERS_INCLUDE != *api* ) || $IMMICH_WORKERS_EXCLUDE == *api* ]]; then - echo "API worker excluded, skipping"; - exit 0; + echo "API worker excluded, skipping" + exit 0 fi IMMICH_HOST="${IMMICH_HOST:-localhost}" @@ -12,11 +18,13 @@ result=$(curl -fsS -m 2 http://"$IMMICH_HOST":"$IMMICH_PORT"/api/server/ping) result_exit=$? if [ $result_exit != 0 ]; then - echo "Fail: exit code is $result_exit"; - exit 1; + echo "Fail: exit code is $result_exit" + log_container_verbose "Healthcheck failed: exit code $result_exit" + exit 1 fi -if [ "$result" != "{\"res\":\"pong\"}" ]; then - echo "Fail: didn't reply with pong"; - exit 1; +if [ "$result" != '{"res":"pong"}' ]; then + echo "Fail: didn't reply with pong" + log_container_verbose "Healthcheck failed: didn't reply with pong" + exit 1 fi