3 # ============LICENSE_START=======================================================
5 # ================================================================================
6 # Copyright (C) 2018 AT&T Intellectual Property. All rights
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
13 # http://www.apache.org/licenses/LICENSE-2.0
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 # ===================================================================
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"
33 LOADED_FLAG=$SAVED_OBJECTS_ROOT/.loaded
35 if [ -f $LOADED_FLAG ];
37 echo "---- Kibana saved objects already restored. Remove $LOADED_FLAG if you want to restore them again."
38 elif [ -n "$(ls -A ${SAVED_OBJECTS_PATH})" ];
40 echo "---- Waiting for elasticsearch to be up..."
43 elastic_url=$(grep elasticsearch.url /usr/share/kibana/config/kibana.yml | cut -d\ -f2)
44 while [ ! "$RES" -eq "0" ] && [ "$PING_TIMEOUT" -gt "0" ];
49 let PING_TIMEOUT=$PING_TIMEOUT-$WAIT_TIME
52 echo "---- Saved objects found, restoring files."
57 # Wait for log file to be avaiable
59 while [ ! -f $LOG_FILE ] && [ "$LOG_TIMEOUT" -gt "0" ];
61 echo "Waiting for $LOG_FILE to be available..."
63 let LOG_TIMEOUT=$LOG_TIMEOUT-$WAIT_TIME
69 # Wait for kibana to be listening
70 while [ -z "$(grep "Server running at" $LOG_FILE)" ] && [ "$TIMEOUT" -gt "0" ];
72 echo "Waiting for kibana to start..."
74 let TIMEOUT=$TIMEOUT-$WAIT_TIME
79 for saved_objects_path in $SAVED_OBJECTS_ROOT/*
81 # skip files as we only need directories
82 [ -f $saved_objects_path ] && continue
84 echo "Restoring content of $saved_objects_path"
85 $RESTORE_CMD -C $saved_objects_path
92 echo "WARNING: Could not save $LOADED_FLAG, saved objects will be restored on next startup." >&2
99 echo "---- No saved object found"
100 ls -A ${SAVED_OBJECTS_PATH}
103 echo "---- Starting kibana"