forked from IsantePlus/wait-for-openmrs-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·42 lines (31 loc) · 1004 Bytes
/
entrypoint.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
#!/usr/local/bin/bash
url=${1:-"http://isanteplus:8080/openmrs"}
interval=${2:-10}
timeout=${3:-100}
START_TIME=$(date +%s)
TIMEOUT_END=$(($START_TIME + $timeout))
while :; do
echo "Waiting for $url"
fhir=0
if [ $fhir -eq 0 ]; then
response=$(curl --max-time 2 -u admin:Admin123 -s -w "\n%{http_code}" $url/ws/fhir2/R4/metadata?_format=json)
response=(${response[@]}) # convert to array
code=${response[-1]} # get last element (last line)
body=${response[@]::${#response[@]}-1} # get all elements except last
if [[ "${body[0]}" == *"CapabilityStatement"* ]]; then
echo "Got FHIR Metadata after $(($(date +%s)-$START_TIME)) seconds!"
fhir=1
fi
fi
if [[ $fhir -eq 1 ]]; then
echo "Exiting!"
exit 0
else
echo "Got Code $code... Still waiting!"
fi
if [ $(date +%s) -ge $TIMEOUT_END ]; then
echo "Operation timed out!"
exit 1
fi
sleep $interval
done