hue.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/bash
  2. # Copyright (c) 2019 Cloudera, Inc. All rights reserved.
  3. set -x
  4. # Time marker for both stderr and stdout
  5. date; date 1>&2
  6. export DESKTOP_LOG_DIR="/var/log/hive"
  7. export PYTHON_EGG_CACHE=$HUE_CONF_DIR/.python-eggs
  8. export SERVER_SOFTWARE="apache"
  9. function prepare_huedb() {
  10. (
  11. flock -x 124
  12. $HUE_BIN/hue syncdb --noinput
  13. $HUE_BIN/hue makemigrations --noinput --merge
  14. $HUE_BIN/hue migrate
  15. ) 124>$HUE_CONF_DIR/hue.lock
  16. }
  17. function db_connectivity_check() {
  18. i=1
  19. ret="fail"
  20. # perform db connectivity check for at least 60 times,
  21. # before give up
  22. while [[ $i -lt 61 ]]; do
  23. # Run hue dbshell, if successful then one should not see
  24. # psql in the output.
  25. dbshell_output=$(echo "\q"|$HUE_BIN/hue dbshell 2>&1)
  26. error_line=$(echo $dbshell_output|grep psql)
  27. if [[ $error_line -eq 0 ]]; then
  28. echo "Successful db connectivity check"
  29. ret="success"
  30. break
  31. fi
  32. i=$((i+1))
  33. # gradually increase sleep time
  34. sleep $i
  35. echo "Failing db connectivity error: " $i " " $dbshell_output
  36. done
  37. echo "$ret"
  38. }
  39. function set_samlcert() {
  40. mkdir -pm 755 $HUE_CONF_DIR/samlcert
  41. cd $HUE_CONF_DIR/samlcert
  42. export RANDFILE=$HUE_CONF_DIR/samlcert/.rnd
  43. if [ -z ${PASSPHRASE+x} ]; then
  44. openssl genrsa -des3 -passout pass:cloudera -out server.pass.key 2048
  45. openssl rsa -inform PEM -outform PEM -passin pass:cloudera -in server.pass.key -out server.key
  46. openssl req -new -key server.key -out server.csr -subj "/C=US/ST=California/L=Palo Alto/O=Cloudera/OU=Hue/CN=$EXTERNAL_HOST"
  47. openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
  48. else
  49. echo "echo \$PASSPHRASE" > $HUE_CONF_DIR/samlcert/pass.key
  50. openssl genrsa -des3 -passout pass:$PASSPHRASE -out server.key 2048
  51. openssl req -new -key server.key -out server.csr -passin pass:$PASSPHRASE -subj "/C=US/ST=California/L=Palo Alto/O=Cloudera/OU=Hue/CN=$EXTERNAL_HOST"
  52. openssl x509 -req -days 365 -in server.csr -passin pass:$PASSPHRASE -signkey server.key -out server.crt
  53. fi
  54. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64
  55. }
  56. # If database connectivity is not set then fail
  57. ret=$(db_connectivity_check)
  58. if [[ $ret == "fail" ]]; then
  59. exit 1
  60. fi
  61. # prepare db schema, run it in single instance flock mode
  62. prepare_huedb
  63. if [[ $1 == kt_renewer ]]; then
  64. if [ -e "/etc/hue/conf/kerberos.ini" ]; then
  65. # The Kerberos ticket renewer role needs to know where kinit is.
  66. KINIT_PATH=`which kinit`
  67. KINIT_PATH=${KINIT_PATH-/usr/bin/kinit}
  68. $HUE_BIN/hue kt_renewer
  69. fi
  70. elif [[ $1 == runcpserver ]]; then
  71. if [ -e "/etc/hue/conf/saml.ini" ]; then
  72. set_samlcert
  73. fi
  74. $HUE_BIN/hue runcherrypyserver
  75. fi
  76. exit 0