-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathpost-start
executable file
·57 lines (44 loc) · 1.33 KB
/
post-start
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
#!/bin/bash
set -euo pipefail
TIMESTAMP_FORMAT="+%Y-%m-%d %H:%M:%S.%3N"
<% if_p("uaa.logging.format.timestamp") do |timestampConfig| %>
timestamp_config="<%= timestampConfig %>"
if [ ${timestamp_config} == "rfc3339" ]; then
TIMESTAMP_FORMAT="+%Y-%m-%dT%H:%M:%S.%NZ"
fi
<% end %>
function log {
echo "[$(date "${TIMESTAMP_FORMAT}")] uaa-post-start - $1"
}
log "Starting"
TS_DIR=/var/vcap/data/uaa/post-start
mkdir -p ${TS_DIR}
WHEN_FINISH=${TS_DIR}/when-finish.timestamp
WHEN_NOW=${TS_DIR}/when-now.timestamp
delete_ts_files() {
rm -f "${WHEN_FINISH}"
rm -f "${WHEN_NOW}"
log "Cleaned up timestamp files"
}
touch -d "10 minutes" "${WHEN_FINISH}" # this creates a file with a timestamp 10 minutes in the future
touch "${WHEN_NOW}"
log "Performing post start healthcheck until $(stat $WHEN_FINISH -c '%y')"
# "-ot" is "older than"
while [ "${WHEN_NOW}" -ot "${WHEN_FINISH}" ]; do
log "Running health check"
set +e # allow the script to continue even when health_check fails
/var/vcap/jobs/uaa/bin/health_check
check=$?
set -e
if [ "$check" -eq "0" ]
then
log "Health check successful"
delete_ts_files
exit 0
fi
sleep 1
touch "${WHEN_NOW}"
done
log "FAILED: Health check failed. Timed out. Check uaa.log to find out why the server failed to start."
delete_ts_files
exit 1