Skip to content

Commit fcab08a

Browse files
committed
Update liveness for minute replication job
1 parent bc77258 commit fcab08a

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

images/replication-job/liveness.sh

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,44 @@
11
#!/usr/bin/env bash
2-
# This is a script for the complex evaluation of whether Osmosis or other processes are running in the container.
3-
if [ $(ps -ef | grep -E 'java' | grep -v grep | wc -l) -ge 1 ]; then
2+
# Script to check if Osmosis (Java) is running and also check how old processed_files.log is.
3+
# If processed_files.log is older than MAX_AGE_MINUTES, then kill Osmosis.
4+
5+
LOG_FILE="/mnt/data/processed_files.log"
6+
MAX_AGE_MINUTES=10
7+
8+
get_file_age_in_minutes() {
9+
local file="$1"
10+
if [ ! -f "$file" ]; then
11+
echo 999999
12+
return
13+
fi
14+
local now
15+
local mtime
16+
now=$(date +%s)
17+
mtime=$(stat -c %Y "$file")
18+
local diff=$(( (now - mtime) / 60 ))
19+
echo "$diff"
20+
}
21+
22+
# Check if Osmosis (Java) is running
23+
OSMOSIS_COUNT=$(ps -ef | grep -E 'java.*osmosis' | grep -v grep | wc -l)
24+
25+
if [ "$OSMOSIS_COUNT" -ge 1 ]; then
426
echo "Osmosis is running."
5-
exit 0
27+
# Check how old the processed_files.log file is
28+
file_age=$(get_file_age_in_minutes "$LOG_FILE")
29+
echo "processed_files.log file age in minutes: $file_age"
30+
if [ "$file_age" -ge "$MAX_AGE_MINUTES" ]; then
31+
echo "processed_files.log is older than $MAX_AGE_MINUTES minutes. Attempting to kill Osmosis and restart the container..."
32+
# Kill the Osmosis process
33+
pkill -f "java.*osmosis" || true
34+
echo "Osmosis is not terminating. Force-killing the container..."
35+
echo "Container force-restart triggered."
36+
exit 2
37+
else
38+
echo "processed_files.log is not too old. No action needed."
39+
exit 0
40+
fi
641
else
7-
echo "Osmosis is not running!" 1>&2
42+
echo "Osmosis is not running!"
843
exit 1
944
fi

0 commit comments

Comments
 (0)