Browse Source

HUE-9195 [Hue] Perform database connection check in when docker container booting up in kubernetes environment (#1071)

Prakash Ranade 5 years ago
parent
commit
11d0a8adc9
1 changed files with 8 additions and 7 deletions
  1. 8 7
      tools/container/hue/hue.sh

+ 8 - 7
tools/container/hue/hue.sh

@@ -20,17 +20,18 @@ function prepare_huedb() {
 }
 
 function db_connectivity_check() {
-  i=3
+  i=1
   ret="fail"
 
   # perform db connectivity check for at least 60 times,
   # before give up
   while [[ $i -lt 61 ]]; do
-    echo "Running db connectivity check"
-
-    status=$(echo quit|$HUE_BIN/hue dbshell 2>&1|wc -l)
-    # check if db connection is successful
-    if [[ $status -gt 1 ]]; then
+    # Run hue dbshell, if successful then one should not see
+    # psql in the output.
+    dbshell_output=$(echo "\q"|$HUE_BIN/hue dbshell 2>&1)
+    error_line=$(echo $dbshell_output|grep psql)
+    if [[ $error_line -eq 0 ]]; then
+      echo "Successful db connectivity check"
       ret="success"
       break
     fi
@@ -39,7 +40,7 @@ function db_connectivity_check() {
     # gradually increase sleep time
     sleep $i
 
-    echo "Failing db connectivity check: " $i
+    echo "Failing db connectivity error: " $i " " $dbshell_output
   done
 
   echo "$ret"