|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright The OpenTelemetry Authors |
| 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 implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +wait_for_cassandra () { |
| 18 | + for ((i = 0; i < 5; ++i)); do |
| 19 | + if docker exec "$1" nodetool status | grep "^UN"; then |
| 20 | + exit 0 |
| 21 | + fi |
| 22 | + echo "Cassandra not yet available" |
| 23 | + sleep 10 |
| 24 | + done |
| 25 | + echo "Timeout waiting for cassandra to initialize" |
| 26 | + exit 1 |
| 27 | +} |
| 28 | + |
| 29 | +wait_for_mongo () { |
| 30 | + for ((i = 0; i < 5; ++i)); do |
| 31 | + if docker exec "$1" mongo; then |
| 32 | + exit 0 |
| 33 | + fi |
| 34 | + echo "Mongo not yet available..." |
| 35 | + sleep 10 |
| 36 | + done |
| 37 | + echo "Timeout waiting for mongo to initialize" |
| 38 | + exit 1 |
| 39 | +} |
| 40 | + |
| 41 | +if [ -z "$CMD" ]; then |
| 42 | + echo "CMD is undefined. exiting..." |
| 43 | + exit 1 |
| 44 | +elif [ -z "$IMG_NAME" ]; then |
| 45 | + echo "IMG_NAME is undefined. exiting..." |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +if [ "$CMD" == "cassandra" ]; then |
| 50 | + wait_for_cassandra "$IMG_NAME" |
| 51 | +elif [ "$CMD" == "mongo" ]; then |
| 52 | + wait_for_mongo "$IMG_NAME" |
| 53 | +else |
| 54 | + echo "unknown CMD" |
| 55 | + exit 1 |
| 56 | +fi |
0 commit comments