From f180ae70f9ecf7a7d1dd52c49ef24efafe1c71c9 Mon Sep 17 00:00:00 2001 From: 000yesnt <49329895+000yesnt@users.noreply.github.com> Date: Mon, 16 Dec 2024 12:19:18 -0300 Subject: [PATCH] feat(server): add Bash healthcheck script (#14704) * feat(server): add Bash healthcheck script * fix(server): add 2 second timeout for healthcheck.js parity * chore(server): delete old healthcheck Node script * fix(server): feedback --------- Co-authored-by: Alex --- server/bin/immich-healthcheck | 21 ++++++++++++++++++++- server/src/bin/healthcheck.ts | 35 ----------------------------------- 2 files changed, 20 insertions(+), 36 deletions(-) delete mode 100644 server/src/bin/healthcheck.ts diff --git a/server/bin/immich-healthcheck b/server/bin/immich-healthcheck index cf0accb8dd..81528157e4 100755 --- a/server/bin/immich-healthcheck +++ b/server/bin/immich-healthcheck @@ -1,3 +1,22 @@ #!/usr/bin/env bash -node /usr/src/app/dist/bin/healthcheck.js +if [[ ( $IMMICH_WORKERS_INCLUDE != '' && $IMMICH_WORKERS_INCLUDE != *api* ) || $IMMICH_WORKERS_EXCLUDE == *api* ]]; then + echo "API worker excluded, skipping"; + exit 0; +fi + +IMMICH_HOST="${IMMICH_HOST:-localhost}" +IMMICH_PORT="${IMMICH_PORT:-2283}" + +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; +fi + +if [ "$result" != "{\"res\":\"pong\"}" ]; then + echo "Fail: didn't reply with pong"; + exit 1; +fi diff --git a/server/src/bin/healthcheck.ts b/server/src/bin/healthcheck.ts deleted file mode 100644 index 2613ee6a19..0000000000 --- a/server/src/bin/healthcheck.ts +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env node -import { ImmichWorker } from 'src/enum'; -import { ConfigRepository } from 'src/repositories/config.repository'; - -const main = async () => { - const { host, workers, port } = new ConfigRepository().getEnv(); - if (!workers.includes(ImmichWorker.API)) { - process.exit(); - } - - const controller = new AbortController(); - const timeout = setTimeout(() => controller.abort(), 2000); - try { - const response = await fetch(`http://${host || 'localhost'}:${port}/api/server/ping`, { - signal: controller.signal, - }); - - if (response.ok) { - const body = await response.json(); - if (body.res === 'pong') { - process.exit(); - } - } - } catch (error) { - if (error instanceof DOMException === false) { - console.error(error); - } - } finally { - clearTimeout(timeout); - } - - process.exit(1); -}; - -void main();