-
Notifications
You must be signed in to change notification settings - Fork 15
/
postflight_checks.sh
executable file
·59 lines (45 loc) · 1.61 KB
/
postflight_checks.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
#!/bin/sh
set -e
. ./utils.sh
command_exists() {
command -v "$@" >/dev/null 2>&1
}
if ! command_exists jq; then
print_error "Post-flight checks require jq to be installed. Please install jq and retry (https://stedolan.github.io/jq/download/)"
exit 1
fi
if ! command_exists curl; then
print_error "Post-flight checks require curl to be installed. Please install curl and retry (https://curl.se/download.html)"
exit 1
fi
if [ -z "$timeout_minutes" ]; then
timeout_minutes=20
fi
if [ -z "$retry_interval_seconds" ]; then
retry_interval_seconds=5
fi
if [ -z "$unhealthy_retries" ]; then
unhealthy_retries=3
fi
remaining_timeout_seconds=$((timeout_minutes * 60))
remaining_unhealthy_retries=$unhealthy_retries
health_endpoint="$(grep 'API_PUBLIC_BASE_URL' sublime.env | cut -d'=' -f2)/v1/health"
while [ $remaining_timeout_seconds -gt 0 ]; do
print_info "Attempting to check Sublime Platform health"
if [ "$(curl -s "$health_endpoint" | jq '.success')" = "true" ]; then
print_success "** Sublime Platform is healthy! **"
exit 0
fi
if [ "$(curl -s "$health_endpoint" | jq '.success')" = "false" ]; then
remaining_unhealthy_retries=$((remaining_unhealthy_retries - 1))
fi
if [ "$remaining_unhealthy_retries" -lt 0 ]; then
print_error "Sublime Platform is unhealthy. See details below:"
curl -s "$health_endpoint" | jq '.'
exit 1
fi
remaining_timeout_seconds=$((remaining_timeout_seconds - retry_interval_seconds))
sleep "$retry_interval_seconds"
done
print_error "Unable to check Sublime Platform health due to timeout"
exit 1