hue_sync_ldap_groups_cron.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/bash
  2. # Licensed to Cloudera, Inc. under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. Cloudera, Inc. licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. #Cron script to sync ldap groups via cron
  18. PARCEL_DIR=/opt/cloudera/parcels/CDH
  19. DATE=`date '+%Y%m%d-%H%M'`
  20. LOG_FILE=/var/log/hue/`basename "$0" | awk -F\. '{print $1}'`.log
  21. LOG_ROTATE_SIZE=10 #MB before rotating, size in MB before rotating log to .1
  22. LOG_ROTATE_COUNT=2 #number of log files, so 20MB max
  23. if [[ ! ${USER} =~ .*root* ]]
  24. then
  25. echo "Script must be run as root: exiting"
  26. exit 1
  27. fi
  28. if [[ -f ${LOG_FILE} ]]
  29. then
  30. LOG_SIZE=`du -sm ${LOG_FILE} | awk '{print $1}'`
  31. if [[ ${LOG_SIZE} -gt ${ROTATE_SIZE} ]]
  32. then
  33. mv ${LOG_FILE} ${LOG_FILE}.1
  34. fi
  35. fi
  36. if [ ! -d "/usr/lib/hadoop" ]
  37. then
  38. CDH_HOME=$PARCEL_DIR
  39. else
  40. CDH_HOME=/usr
  41. fi
  42. if [ -d "/var/run/cloudera-scm-agent/process" ]
  43. then
  44. HUE_CONF_DIR="/var/run/cloudera-scm-agent/process/`ls -1 /var/run/cloudera-scm-agent/process | grep HUE | sort -n | tail -1 `"
  45. else
  46. HUE_CONF_DIR="/etc/hue/conf"
  47. fi
  48. if [ -d "${CDH_HOME}/lib/hue/build/env/bin" ]
  49. then
  50. COMMAND="${CDH_HOME}/lib/hue/build/env/bin/hue sync_ldap_users_and_groups"
  51. else
  52. COMMAND="${CDH_HOME}/share/hue/build/env/bin/hue sync_ldap_users_and_groups"
  53. fi
  54. export CDH_HOME HUE_CONF_DIR COMMAND
  55. echo "${DATE} - Syncing Ldap Groups" >> ${LOG_FILE}
  56. echo "${DATE} - HUE_CONF_DIR: ${HUE_CONF_DIR}" >> ${LOG_FILE}
  57. cd /tmp
  58. ${COMMAND} >> ${LOG_FILE}