Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Instrumental | 7a1817b | 2018-11-05 11:11:15 -0600 | [diff] [blame] | 2 | ######### |
| 3 | # ============LICENSE_START==================================================== |
| 4 | # org.onap.aaf |
| 5 | # =========================================================================== |
| 6 | # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved. |
| 7 | # =========================================================================== |
| 8 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | # you may not use this file except in compliance with the License. |
| 10 | # You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, software |
| 15 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | # See the License for the specific language governing permissions and |
| 18 | # limitations under the License. |
| 19 | # ============LICENSE_END==================================================== |
| 20 | # |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 21 | # |
| 22 | # A Script for use in Pods... Check for status files, and validate before moving on. |
| 23 | # |
| 24 | DIR="/opt/app/aaf/status" |
| 25 | APP=$1 |
| 26 | shift |
| 27 | OTHER=$1 |
| 28 | shift |
| 29 | |
| 30 | function status { |
| 31 | if [ -d "$DIR" ]; then |
| 32 | echo "$@" > $DIR/$APP |
| 33 | fi |
| 34 | } |
| 35 | |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 36 | |
| 37 | function check { |
| 38 | if [ -d "$DIR" ]; then |
| 39 | if [ -e "$DIR/$OTHER" ]; then |
| 40 | echo "$(cat $DIR/$OTHER)" |
| 41 | else |
| 42 | echo "$DIR/$OTHER does not exist" |
| 43 | fi |
| 44 | else |
| 45 | echo "$DIR does not exist" |
| 46 | fi |
| 47 | } |
| 48 | |
Instrumental | ca788dc | 2018-11-03 14:38:21 -0500 | [diff] [blame] | 49 | function wait { |
| 50 | n=0 |
| 51 | while [ $n -lt 40 ]; do |
| 52 | rv="$(check)" |
| 53 | echo "$rv" |
| 54 | if [ "$rv" = "ready" ]; then |
| 55 | echo "$OTHER is $rv" |
| 56 | n=10000 |
| 57 | else |
| 58 | (( ++n )) |
| 59 | echo "Sleep 10 (iteration $n)" |
| 60 | sleep 10 |
| 61 | fi |
| 62 | done |
| 63 | } |
| 64 | |
Instrumental | 14f3707 | 2018-10-09 08:32:06 -0500 | [diff] [blame] | 65 | function start { |
| 66 | n=0 |
| 67 | while [ $n -lt 40 ]; do |
| 68 | rv="$(check)" |
| 69 | echo "$OTHER is $rv" |
| 70 | if [ "$rv" = "ready" ]; then |
| 71 | # This is critical. Until status is literally "ready" in the status directory, no processes will start |
| 72 | status ready |
| 73 | echo "Starting $@" |
| 74 | n=10000 |
| 75 | else |
| 76 | (( ++n )) |
| 77 | echo "Sleep 10 (iteration $n)" |
| 78 | sleep 10 |
| 79 | fi |
| 80 | done |
| 81 | } |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 82 | |
Instrumental | ca788dc | 2018-11-03 14:38:21 -0500 | [diff] [blame] | 83 | case "$OTHER" in |
| 84 | sleep) |
| 85 | echo "Sleeping $1" |
| 86 | status "Sleeping $1" |
| 87 | sleep $1 |
| 88 | shift |
| 89 | status "ready" |
| 90 | echo "Done" |
| 91 | ;; |
| 92 | wait) |
| 93 | OTHER="$1" |
| 94 | shift |
| 95 | wait |
| 96 | ;; |
| 97 | *) |
| 98 | echo "App $APP is waiting to start until $OTHER is ready" |
| 99 | status "waiting for $OTHER" |
| 100 | |
| 101 | start |
| 102 | ;; |
| 103 | esac |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 104 | |
Instrumental | 12414fe | 2019-01-22 10:27:32 -0600 | [diff] [blame^] | 105 | eval "$@" |