blob: 07ff98144355723810235953e2c361241b48b85a [file] [log] [blame]
Instrumental08e93402018-10-03 08:38:52 -05001#!/bin/bash
Instrumental7a1817b2018-11-05 11:11:15 -06002#########
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#
Instrumental08e93402018-10-03 08:38:52 -050021#
22# A Script for use in Pods... Check for status files, and validate before moving on.
23#
24DIR="/opt/app/aaf/status"
25APP=$1
26shift
27OTHER=$1
28shift
29
30function status {
31 if [ -d "$DIR" ]; then
32 echo "$@" > $DIR/$APP
33 fi
34}
35
Instrumental08e93402018-10-03 08:38:52 -050036
37function 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
Instrumentalca788dc2018-11-03 14:38:21 -050049function 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
Instrumental14f37072018-10-09 08:32:06 -050065function 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}
Instrumental08e93402018-10-03 08:38:52 -050082
Instrumentalca788dc2018-11-03 14:38:21 -050083case "$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 ;;
103esac
Instrumental08e93402018-10-03 08:38:52 -0500104
Instrumental12414fe2019-01-22 10:27:32 -0600105eval "$@"