Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 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 | |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 17 | |
| 18 | function check { |
| 19 | if [ -d "$DIR" ]; then |
| 20 | if [ -e "$DIR/$OTHER" ]; then |
| 21 | echo "$(cat $DIR/$OTHER)" |
| 22 | else |
| 23 | echo "$DIR/$OTHER does not exist" |
| 24 | fi |
| 25 | else |
| 26 | echo "$DIR does not exist" |
| 27 | fi |
| 28 | } |
| 29 | |
Instrumental | 14f3707 | 2018-10-09 08:32:06 -0500 | [diff] [blame^] | 30 | function start { |
| 31 | n=0 |
| 32 | while [ $n -lt 40 ]; do |
| 33 | rv="$(check)" |
| 34 | echo "$OTHER is $rv" |
| 35 | if [ "$rv" = "ready" ]; then |
| 36 | # This is critical. Until status is literally "ready" in the status directory, no processes will start |
| 37 | status ready |
| 38 | echo "Starting $@" |
| 39 | n=10000 |
| 40 | else |
| 41 | (( ++n )) |
| 42 | echo "Sleep 10 (iteration $n)" |
| 43 | sleep 10 |
| 44 | fi |
| 45 | done |
| 46 | } |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 47 | |
Instrumental | 14f3707 | 2018-10-09 08:32:06 -0500 | [diff] [blame^] | 48 | if [ "sleep" = "$OTHER" ]; then |
| 49 | echo "Sleeping $1" |
| 50 | status "Sleeping $1" |
| 51 | sleep $1 |
| 52 | shift |
| 53 | status "ready" |
| 54 | else |
| 55 | echo "App $APP is waiting to start until $OTHER is ready" |
| 56 | status "waiting for $OTHER" |
| 57 | |
| 58 | start |
| 59 | fi |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 60 | |
| 61 | eval "$@" |