forked from SUSE/fissile-stemcell-SLE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-start.sh
39 lines (34 loc) · 1.4 KB
/
post-start.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
#!/bin/bash
set -o errexit -o xtrace
# Cannot use this generally. Interferes with the check via `monit summary`.
# I.e. when things are ready the failure of grep to match aborts us.
# Check for post-start scripts to run. We may not have any.
#
# * `flock` is used to guard against monit starting this script
# multiple times when our dependency checking and/or the invoked
# scripts are taking too long.
#
# * `monit summary` is used to check if the __other__ jobs are up.
# Nothing is done while they are not up yet. We know that we are
# `post-start`, important to exclude ourselves from the check
#
# Doing our own dependency checking works around issues in monit.
# This can be shifted to monit itself ('depends on') when we reach use
# of monit v5.15+ where the issues are fixed.
(
mkdir -p /var/vcap/sys/log/post-start
exec 1>>/var/vcap/sys/log/post-start/post-start.stdout.log
exec 2>>/var/vcap/sys/log/post-start/post-start.stderr.log
flock -n 9 || exit 1
summary="$(/var/vcap/bosh/bin/monit summary)" # Separate to capture exit status
if printf "%s" "${summary}" | tail -n+3 | grep -v post-start | grep --silent -viw 'accessible\|running'
then
# Other roles not ready, wait a bit more without returning error
exit 0
fi
while read -r f ; do
echo bash "$f"
bash "$f"
done < <(find /var/vcap/jobs/*/bin -name post-start)
touch /var/vcap/monit/ready
) 9> /var/vcap/monit/ready.lock