Create Helm Instantiation
[aaf/authz.git] / auth / sample / bin / pod_wait.sh
1 #!/bin/bash
2 #
3 # A Script for use in Pods... Check for status files, and validate before moving on.
4 #
5 DIR="/opt/app/aaf/status"
6 APP=$1
7 shift
8 OTHER=$1
9 shift
10
11 function status {
12   if [ -d "$DIR" ]; then
13      echo "$@" > $DIR/$APP
14   fi
15 }
16
17 echo $APP $OTHER
18
19 function 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
31 echo "App $APP is waiting to start until $OTHER is ready"
32 status "waiting for $OTHER"
33
34 n=0
35 while [ $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
48 done
49
50 eval "$@"