Skip to content

Commit

Permalink
Merge pull request #603 from geoadmin/fix_readiness_probe
Browse files Browse the repository at this point in the history
improve readiness probe
  • Loading branch information
ltclm authored Feb 1, 2024
2 parents b130f85 + 168c7c6 commit 26f0ae9
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions scripts/checker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,30 @@ set -e
set -u
set -o pipefail

if searchd --status 1> /dev/null; then
exit 0
else
# the service is considered to be ready for connections if
# searchd --status is running
# last sync of index files exists and is not older than 5 minutes

# check if searchd is running
searchd --status 1> /dev/null || exit 1

# check if index files are up-to-date
LAST_SYNC="/tmp/last_sync_finished.txt"
MAX_AGE=300 # max age in seconds should be the same interval as the cron settings

# check if index sync status file exists
if [[ ! -f "${LAST_SYNC}" ]]; then
echo "index sync status file does not exist ${LAST_SYNC}"
exit 1
fi

# Calculate the time MAX_AGE seconds ago in seconds
five_mins_ago=$(( $(date +%s) - MAX_AGE ))
# Get the file's last modification time in seconds
file_mtime=$(stat -c %Y "${LAST_SYNC}")

# check if index sync status file is up-to-date
if [[ $file_mtime -lt $five_mins_ago ]]; then
echo "index sync status file is outdated: ${LAST_SYNC}"
exit 1
fi
fi

0 comments on commit 26f0ae9

Please sign in to comment.