From f8a695e5abec7de4f35a58b3cfc83590f1c4c5f0 Mon Sep 17 00:00:00 2001 From: Samuel Jones Date: Thu, 17 Oct 2024 10:54:45 +0100 Subject: [PATCH] Add liveness bash script --- container/Dockerfile | 2 ++ container/liveness.bash | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100755 container/liveness.bash diff --git a/container/Dockerfile b/container/Dockerfile index d71f602..ee1262d 100644 --- a/container/Dockerfile +++ b/container/Dockerfile @@ -4,4 +4,6 @@ FROM python:3.12-slim@sha256:740d94a19218c8dd584b92f804b1158f85b0d241e5215ea26ed ADD . . RUN python -m pip install --no-cache-dir . +COPY ./container/liveness.bash . + CMD run-detection \ No newline at end of file diff --git a/container/liveness.bash b/container/liveness.bash new file mode 100755 index 0000000..8b66caa --- /dev/null +++ b/container/liveness.bash @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +# Check for heartbeat file +CURRENT_TIME=$(date +%s) +FILE_TIME=$(date -r /tmp/heartbeat +%s) +DIFF=$((CURRENT_TIME - FILE_TIME)) +if [ $DIFF -lt 20 ]; then + exit 0 +else + exit 1 +fi + +# Test for a readable file the archive +FILE_LIST="/archive/NDXLOQ/Instrument/data/cycle_24_3/LOQ00110782.nxs /archive/NDXOSIRIS/Instrument/data/cycle_24_3/OSIRIS00149339.nxs /archive/NDXTOSCA/Instrument/data/cycle_24_3/TSC30650.nxs /archive/NDXMARI/Instrument/data/cycle_23_4/MAR29177.nxs" +for file in $FILE_LIST; do + if ! [ -r "$file" ]; then + exit 1 + fi +done + +# All checks previously passed +exit 0 \ No newline at end of file