ac2550 | ead1051 | 2018-10-05 13:50:23 +0200 | [diff] [blame] | 1 | #!/bin/bash -x |
| 2 | ### |
| 3 | # ============LICENSE_START======================================================= |
| 4 | # ONAP CLAMP |
| 5 | # ================================================================================ |
| 6 | # Copyright (C) 2018 AT&T Intellectual Property. All rights |
| 7 | # reserved. |
| 8 | # ================================================================================ |
| 9 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | # you may not use this file except in compliance with the License. |
| 11 | # You may obtain a copy of the License at |
| 12 | # |
| 13 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | # |
| 15 | # Unless required by applicable law or agreed to in writing, software |
| 16 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | # See the License for the specific language governing permissions and |
| 19 | # limitations under the License. |
| 20 | # ============LICENSE_END============================================ |
| 21 | # =================================================================== |
| 22 | # |
| 23 | ### |
| 24 | KIBANA_CONF_FILE="/usr/share/kibana/config/kibana.yml" |
| 25 | SAVED_OBJECTS_ROOT="/saved-objects/" |
| 26 | RESTORE_CMD="/usr/local/bin/restore.py -H http://127.0.0.1:5601/ -f" |
| 27 | BACKUP_BIN="/usr/local/bin/backup.py" |
| 28 | KIBANA_START_CMD="/usr/local/bin/kibana-docker" |
| 29 | LOG_FILE="/tmp/load.kibana.log" |
| 30 | KIBANA_LOAD_CMD="/usr/local/bin/kibana-docker -H 127.0.0.1 -l $LOG_FILE" |
| 31 | TIMEOUT=60 |
| 32 | WAIT_TIME=2 |
| 33 | |
| 34 | if [ -n "$(ls -A ${SAVED_OBJECTS_PATH})" ]; |
| 35 | then |
| 36 | echo "---- Saved objects found, restoring files." |
| 37 | |
| 38 | $KIBANA_LOAD_CMD & |
| 39 | KIB_PID=$! |
| 40 | |
| 41 | # Wait for log file to be avaiable |
| 42 | LOG_TIMEOUT=60 |
| 43 | while [ ! -f $LOG_FILE ] && [ "$LOG_TIMEOUT" -gt "0" ]; |
| 44 | do |
| 45 | echo "Waiting for $LOG_FILE to be available..." |
| 46 | sleep $WAIT_TIME |
| 47 | let LOG_TIMEOUT=$LOG_TIMEOUT-$WAIT_TIME |
| 48 | done |
| 49 | |
| 50 | tail -f $LOG_FILE & |
| 51 | LOG_PID=$! |
| 52 | |
| 53 | # Wait for kibana to be listening |
| 54 | while [ -z "$(grep "Server running at" $LOG_FILE)" ] && [ "$TIMEOUT" -gt "0" ]; |
| 55 | do |
| 56 | echo "Waiting for kibana to start..." |
| 57 | sleep $WAIT_TIME |
| 58 | let TIMEOUT=$TIMEOUT-$WAIT_TIME |
| 59 | done |
| 60 | sleep 1 |
| 61 | |
| 62 | # restore files |
| 63 | for saved_objects_path in $SAVED_OBJECTS_ROOT/* |
| 64 | do |
| 65 | echo "Restoring content of $saved_objects_path" |
| 66 | $RESTORE_CMD -C $saved_objects_path |
| 67 | sleep 1 |
| 68 | done |
| 69 | |
| 70 | # cleanup |
| 71 | kill $KIB_PID |
| 72 | kill $LOG_PID |
| 73 | else |
| 74 | echo "---- No saved object found" |
| 75 | ls -A ${SAVED_OBJECTS_PATH} |
| 76 | fi |
| 77 | |
| 78 | echo "---- Starting kibana" |
| 79 | |
| 80 | $KIBANA_START_CMD |
| 81 | |