blob: 3d6a1b9ec481285591b802886fd56a76729ca364 [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
Instrumentalaae5c072019-03-29 15:42:37 -050032 echo "$@" > $DIR/$APP-$HOSTNAME
Instrumental08e93402018-10-03 08:38:52 -050033 fi
34}
35
Instrumental08e93402018-10-03 08:38:52 -050036
37function check {
38 if [ -d "$DIR" ]; then
Instrumentalaae5c072019-03-29 15:42:37 -050039 if [ -z "$(ls $DIR/$OTHER* 2> /dev/null)" ]; then
Instrumental08e93402018-10-03 08:38:52 -050040 echo "$DIR/$OTHER does not exist"
Instrumentalaae5c072019-03-29 15:42:37 -050041 else
42 echo "$(cat $DIR/$OTHER*)"
Instrumental08e93402018-10-03 08:38:52 -050043 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"
Instrumentalaae5c072019-03-29 15:42:37 -050054 if [ -z "$(echo $rv | grep "ready")" ]; then
Instrumentalca788dc2018-11-03 14:38:21 -050055 (( ++n ))
56 echo "Sleep 10 (iteration $n)"
57 sleep 10
Instrumentalaae5c072019-03-29 15:42:37 -050058 else
59 echo "$OTHER is $rv"
60 n=10000
Instrumentalca788dc2018-11-03 14:38:21 -050061 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"
Instrumentalaae5c072019-03-29 15:42:37 -050070 if [ -z "$(echo $rv | grep "ready")" ]; then
71 (( ++n ))
72 echo "Sleep 10 (iteration $n)"
73 sleep 10
74 else
Instrumental14f37072018-10-09 08:32:06 -050075 # This is critical. Until status is literally "ready" in the status directory, no processes will start
76 status ready
77 echo "Starting $@"
78 n=10000
Instrumental14f37072018-10-09 08:32:06 -050079 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 ;;
Instrumentalaae5c072019-03-29 15:42:37 -050092 stop)
93 echo "Removing $DIR/$APP-$HOSTNAME"
94 rm $DIR/$APP-$HOSTNAME
95 ;;
Instrumentalca788dc2018-11-03 14:38:21 -050096 wait)
97 OTHER="$1"
98 shift
99 wait
100 ;;
101 *)
102 echo "App $APP is waiting to start until $OTHER is ready"
103 status "waiting for $OTHER"
104
105 start
106 ;;
107esac
Instrumental08e93402018-10-03 08:38:52 -0500108
Instrumentalaae5c072019-03-29 15:42:37 -0500109eval "$@"