Skip to content

Commit 3d86f6d

Browse files
authored
Merge pull request #658 from geoadmin/master
Master
2 parents d88c0f0 + b5e0a87 commit 3d86f6d

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

scripts/checker.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ searchd --status 1> /dev/null || exit 1
1212

1313
# check if index files are up-to-date
1414
LAST_SYNC="/tmp/last_sync_finished.txt"
15-
MAX_AGE=300 # max age in seconds should be the same interval as the cron settings
15+
# max age in seconds, default value should be at least the same interval as the cron settings in docker-crontab, default 5 minutes (300 seconds)
16+
# in productive systems it is better to use a higher value, e.g. 2x300s = 600s
17+
MAX_AGE=${MAX_AGE:-300}
1618

1719
# check if index sync status file exists
1820
if [[ ! -f "${LAST_SYNC}" ]]; then
@@ -22,13 +24,16 @@ if [[ ! -f "${LAST_SYNC}" ]]; then
2224
exit 1
2325
fi
2426

25-
# Calculate the time MAX_AGE seconds ago in seconds
26-
five_mins_ago=$(( $(date +%s) - MAX_AGE ))
27-
# Get the file's last modification time in seconds
28-
file_mtime=$(stat -c %Y "${LAST_SYNC}")
27+
# check if index-sync-rotate.sh is currently running with the lock file
28+
# if a sync is currently running, further tests should not be executed
29+
LOCK_FILE="/tmp/index-sync-rotate.sh"
30+
if ! flock -n "${LOCK_FILE}" true ; then
31+
echo "$(basename "${LOCK_FILE}") is currently running. Exiting."
32+
exit 0
33+
fi
2934

3035
# check if index sync status file is up-to-date
31-
if [[ $file_mtime -lt $five_mins_ago ]]; then
36+
if [[ $(stat -c %Y "${LAST_SYNC}") -lt $(( $(date +%s) - MAX_AGE )) ]]; then
3237
echo "index sync status file is outdated: ${LAST_SYNC}"
3338
exit 1
3439
fi

0 commit comments

Comments
 (0)