-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathhealthcheck.sh
More file actions
77 lines (66 loc) · 1.82 KB
/
healthcheck.sh
File metadata and controls
77 lines (66 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# Health check script for Leapcell.io
MAX_RETRIES=5
RETRY_INTERVAL=2
PORT=8080
echo "Starting health check..."
# Check if curl is installed
if ! command -v curl &> /dev/null; then
echo "curl is not installed. Installing..."
apt-get update && apt-get install -y curl
fi
# Check if the process is running
check_process() {
if pgrep -f "python.*quickinfo.py" > /dev/null; then
echo "Bot process is running"
return 0
else
echo "Bot process is not running"
return 1
fi
}
# Check the health endpoint
check_endpoint() {
for i in $(seq 1 $MAX_RETRIES); do
echo "Checking health endpoint (Attempt $i of $MAX_RETRIES)..."
response=$(curl -s -o /dev/null -w "%{http_code}" http://127.0.0.1:$PORT/kaithheathcheck)
if [ "$response" = "200" ]; then
echo "Health endpoint check passed!"
return 0
fi
echo "Attempt $i failed. Retrying in $RETRY_INTERVAL seconds..."
sleep $RETRY_INTERVAL
done
echo "Health endpoint check failed after $MAX_RETRIES attempts"
return 1
}
# Check MongoDB connection
check_mongodb() {
if nc -z -w5 $(echo $MONGODB_URL | cut -d'@' -f2 | cut -d'/' -f1 | cut -d':' -f1) \
$(echo $MONGODB_URL | cut -d'@' -f2 | cut -d'/' -f1 | cut -d':' -f2); then
echo "MongoDB connection check passed!"
return 0
else
echo "MongoDB connection check failed!"
return 1
fi
}
# Main health check function
main_health_check() {
# Check process
if ! check_process; then
exit 1
fi
# Check endpoint
if ! check_endpoint; then
exit 1
fi
# Check MongoDB
if ! check_mongodb; then
exit 1
fi
echo "All health checks passed successfully!"
exit 0
}
# Execute the main health check
main_health_check