-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
healthcheck.sh
95 lines (86 loc) · 3.81 KB
/
healthcheck.sh
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# Check for at least one running instance of str2str
str2str_count=$(pgrep -c str2str)
if [ "$str2str_count" -lt 2 ]; then
# If no str2str instance is found, exit with error (unhealthy)
echo "Health Check: No running instance of str2str found. Exiting with error."
exit 1
else
echo "Health Check: Found running instance(s) of str2str."
fi
# Initial count of ntripserver and adjusted str2str count
ntripserver_count=0
str2str_count=2
# Boolean flag for server checks
ntripservercheck=false
str2strcheck=false
stunnelcheck=false
check_onocoy_ssl=false
# Adjust ntripserver and str2str count based on conditions that require them in the docker-init.sh
if [ "$RTKDIRECT_USE_NTRIPSERVER" = true ] && [ -n "$RTKDIRECT_USERNAME" ] && [ -n "$RTKDIRECT_MOUNTPOINT" ] && [ -n "$RTKDIRECT_PASSWORD" ]; then
ntripserver_count=$((ntripserver_count + 1))
echo "Health Check: RTKDIRECT configuration requires NTRIPSERVER."
elif [ "$RTKDIRECT_USE_NTRIPSERVER" != true ] && [ -n "$RTKDIRECT_USERNAME" ] && [ -n "$RTKDIRECT_MOUNTPOINT" ] && [ -n "$RTKDIRECT_PASSWORD" ]; then
str2str_count=$((str2str_count + 1))
echo "Health Check: RTKDIRECT configuration requires additional str2str instance."
fi
if [ -n "$ONOCOY_MOUNTPOINT" ] || [ "$ONOCOY_USE_NTRIPSERVER" = true ]; then
ntripserver_count=$((ntripserver_count + 1))
check_onocoy_ssl=true
echo "Health Check: ONOCOY configuration requires NTRIPSERVER."
elif [ -z "$ONOCOY_MOUNTPOINT" ] && [ "$ONOCOY_USE_NTRIPSERVER" != true ] && [ -n "$ONOCOY_USERNAME" ] && [ -n "$ONOCOY_PASSWORD" ]; then
str2str_count=$((str2str_count + 1))
check_onocoy_ssl=true
echo "Health Check: ONOCOY configuration requires additional str2str instance."
fi
# Check NTRIPSERVER Count
if [ "$ntripserver_count" -eq 0 ]; then
echo "Health Check: No NTRIPSERVER required. Skipping NTRIPSERVER check."
ntripservercheck=true
else
# If ntripserver is needed, check if the required number of ntripserver instances are running
if [ "$(pgrep -c ntripserver)" -ge "$ntripserver_count" ]; then
echo "Health Check: Required number of NTRIPSERVER instances are running."
ntripservercheck=true
else
echo "Health Check: Required number of NTRIPSERVER instances are not running."
ntripservercheck=false
fi
fi
# Check STR2STR Count
if [ "$str2str_count" -eq 1 ]; then
echo "Health Check: No additional STR2STR required. Skipping STR2STR check."
str2strcheck=true
else
# If str2str is needed, check if the required number of str2str instances are running
if [ "$(pgrep -c str2str)" -ge "$str2str_count" ]; then
echo "Health Check: Required number of STR2STR instances are running."
str2strcheck=true
else
echo "Health Check: Required number of STR2STR instances are not running."
str2strcheck=false
fi
fi
# Check for a single instance of stunnel if ONOCOY_USE_SSL is enabled and check_onocoy_ssl exists and is true
if [ "$ONOCOY_USE_SSL" = true ] && [ "$check_onocoy_ssl" = true ]; then
stunnel_count=$(pgrep -c stunnel)
if [ "$stunnel_count" -ne 1 ]; then
echo "Health Check: Required single instance of stunnel is not running."
stunnelcheck=false
else
echo "Health Check: Required single instance of stunnel is running."
stunnelcheck=true
fi
else
echo "Health Check: stunnel is not required. Skipping stunnel check."
stunnelcheck=true
fi
if [ "$ntripservercheck" = false ] || [ "$str2strcheck" = false ] || [ "$stunnelcheck" = false ]; then
# If any check is false, exit with error (unhealthy)
echo "Health Check: One or more required services are not running. Exiting with error."
exit 1
else
# If all checks are true, exit with success (healthy)
echo "Health Check: All required services are running. Exiting with success."
exit 0
fi