blob: 71773be7ec49046faaf73a746c530870f727cefb [file] [log] [blame]
Instrumental08e93402018-10-03 08:38:52 -05001#!/bin/bash
2#
3# A Script for use in Pods... Check for status files, and validate before moving on.
4#
5DIR="/opt/app/aaf/status"
6APP=$1
7shift
8OTHER=$1
9shift
10
11function status {
12 if [ -d "$DIR" ]; then
13 echo "$@" > $DIR/$APP
14 fi
15}
16
17echo $APP $OTHER
18
19function check {
20 if [ -d "$DIR" ]; then
21 if [ -e "$DIR/$OTHER" ]; then
22 echo "$(cat $DIR/$OTHER)"
23 else
24 echo "$DIR/$OTHER does not exist"
25 fi
26 else
27 echo "$DIR does not exist"
28 fi
29}
30
31echo "App $APP is waiting to start until $OTHER is ready"
32status "waiting for $OTHER"
33
34n=0
35while [ $n -lt 40 ]; do
36 rv="$(check)"
37 echo "$OTHER is $rv"
38 if [ "$rv" = "ready" ]; then
39 # This is critical. Until status is literally "ready" in the status directory, no processes will start
40 status ready
41 echo "Starting $@"
42 n=10000
43 else
44 (( ++n ))
45 echo "Sleep 10 (iteration $n)"
46 sleep 10
47 fi
48done
49
50eval "$@"