blob: e7c8065edb68c890cb93589bc318166dacb3ab1e [file] [log] [blame]
Mike Marchetti9d9192b2018-09-21 12:03:05 -04001#!/bin/sh
2
vijaynag8339ed22019-07-25 17:10:58 +05303# Copyright 2019 ETSI
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14# implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
garciadeblas0dc45d82018-12-20 17:10:27 +010018WAIT_TIME=340 # LCM healthcheck needs 2x(30+140) senconds
beierlmaf26f652020-10-16 21:47:19 +020019SERVICES_WITH_HEALTH="nbi ro zookeeper lcm mon light-ui pol kafka"
tierno84a3c9a2018-10-24 11:02:57 +020020NUM_SERVICES_WITH_HEALTH=$(echo $SERVICES_WITH_HEALTH | wc -w)
Michael Marchetti26e8e332018-11-01 17:12:20 +000021WAIT_FINAL=30
beierlmaf26f652020-10-16 21:47:19 +020022OSM_DEPLOYMENT="light-ui nbi lcm ro mon pol keystone"
vijaynag8339ed22019-07-25 17:10:58 +053023OSM_STATEFULSET="zookeeper kafka mongo mysql prometheus"
24NUM_K8S_PODS=$(echo $OSM_DEPLOYMENT $OSM_STATEFULSET | wc -w)
Mike Marchetti9d9192b2018-09-21 12:03:05 -040025
vijaynag8339ed22019-07-25 17:10:58 +053026while getopts "w:s:n:c:k" o; do
Mike Marchetti9d9192b2018-09-21 12:03:05 -040027 case "${o}" in
28 w)
29 WAIT_TIME=${OPTARG}
30 ;;
31 s)
32 STACK_NAME=${OPTARG}
33 ;;
34 n)
35 NUM_SERVICES_WITH_HEALTH=${OPTARG}
36 ;;
tiernobc983ec2018-10-11 15:03:06 +020037 c)
38 SERVICES_WITH_HEALTH="${OPTARG}"
39 ;;
vijaynag8339ed22019-07-25 17:10:58 +053040 k)
41 KUBERNETES="y"
42 ;;
Mike Marchetti9d9192b2018-09-21 12:03:05 -040043 esac
44done
45
46
47time=0
tierno84a3c9a2018-10-24 11:02:57 +020048step=2
Mike Marchetti9d9192b2018-09-21 12:03:05 -040049while [ $time -le "$WAIT_TIME" ]; do
vijaynag8339ed22019-07-25 17:10:58 +053050 if [ -n "$KUBERNETES" ]; then
51 if [ "$(kubectl get pods -n "${STACK_NAME}" | grep -i running | wc -l)" -ge "$NUM_K8S_PODS" ]; then
52 #all pods are running now.
53 sleep $WAIT_FINAL
54 exit 0
55 fi
56 else
endikaae9807e2020-09-11 15:19:52 +020057 if [ "$(sg docker -c "docker ps" | grep " ${STACK_NAME}_" | grep -i healthy | wc -l)" -ge "$NUM_SERVICES_WITH_HEALTH" ]; then
vijaynag8339ed22019-07-25 17:10:58 +053058 # all dockers are healthy now.
59 # final sleep is needed until more health checks are added to validate system is ready to handle requests
60 sleep $WAIT_FINAL
61 exit 0
62 fi
Mike Marchetti9d9192b2018-09-21 12:03:05 -040063 fi
64
65 sleep $step
66 time=$((time+step))
67done
Mike Marchetti37c3f512018-09-24 10:27:00 -040068
vijaynag8339ed22019-07-25 17:10:58 +053069if [ -n "$KUBERNETES" ]; then
70 echo "Not all pods are running"
71 kubectl get pods -n "${STACK_NAME}"
72 for POD in $OSM_DEPLOYMENT $OSM_STATEFULSET; do
73 kubectl get pods -n "${STACK_NAME}" | grep -i running | grep -q ^"${POD}-" && continue
74 echo
75 echo BEGIN LOGS of pods ${POD} not running
76 LOG_POD=$(kubectl get pods -n "${STACK_NAME}" | grep -e ^"${POD}-" | awk '{print $1}' )
77 [ -z "$LOG_POD" ] && echo "${POD} Failed to deploy" || kubectl logs ${LOG_POD} -n $STACK_NAME 2>&1 | tail -n 100
78 echo END LOGS of services $POD not running
79 done
80else
81 echo "Not all Docker services are healthy"
endikaae9807e2020-09-11 15:19:52 +020082 sg docker -c "docker ps" | grep " ${STACK_NAME}_"
vijaynag8339ed22019-07-25 17:10:58 +053083 for S_WITH_HEALTH in $SERVICES_WITH_HEALTH ; do
endikaae9807e2020-09-11 15:19:52 +020084 sg docker -c "docker ps" | grep " ${STACK_NAME}_" | grep -i healthy | grep -q "_${S_WITH_HEALTH}." && continue
vijaynag8339ed22019-07-25 17:10:58 +053085 echo
86 echo BEGIN LOGS of container ${S_WITH_HEALTH} not healthy
endikaae9807e2020-09-11 15:19:52 +020087 sg docker -c "docker service logs ${STACK_NAME}_${S_WITH_HEALTH} 2>&1" | tail -n 100
vijaynag8339ed22019-07-25 17:10:58 +053088 echo END LOGS of container ${S_WITH_HEALTH} not healthy
89 echo
90 done
91fi
tiernobc983ec2018-10-11 15:03:06 +020092
Mike Marchetti9d9192b2018-09-21 12:03:05 -040093exit 1