Skip to content

Commit 26f0ae9

Browse files
authored
Merge pull request #603 from geoadmin/fix_readiness_probe
improve readiness probe
2 parents b130f85 + 168c7c6 commit 26f0ae9

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

scripts/checker.sh

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,30 @@ set -e
33
set -u
44
set -o pipefail
55

6-
if searchd --status 1> /dev/null; then
7-
exit 0
8-
else
6+
# the service is considered to be ready for connections if
7+
# searchd --status is running
8+
# last sync of index files exists and is not older than 5 minutes
9+
10+
# check if searchd is running
11+
searchd --status 1> /dev/null || exit 1
12+
13+
# check if index files are up-to-date
14+
LAST_SYNC="/tmp/last_sync_finished.txt"
15+
MAX_AGE=300 # max age in seconds should be the same interval as the cron settings
16+
17+
# check if index sync status file exists
18+
if [[ ! -f "${LAST_SYNC}" ]]; then
19+
echo "index sync status file does not exist ${LAST_SYNC}"
20+
exit 1
21+
fi
22+
23+
# Calculate the time MAX_AGE seconds ago in seconds
24+
five_mins_ago=$(( $(date +%s) - MAX_AGE ))
25+
# Get the file's last modification time in seconds
26+
file_mtime=$(stat -c %Y "${LAST_SYNC}")
27+
28+
# check if index sync status file is up-to-date
29+
if [[ $file_mtime -lt $five_mins_ago ]]; then
30+
echo "index sync status file is outdated: ${LAST_SYNC}"
931
exit 1
10-
fi
32+
fi

0 commit comments

Comments
 (0)