PageRenderTime 51ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/release-0.1-rc2/hive/external/bin/init-hive-dfs.sh

#
Shell | 107 lines | 70 code | 17 blank | 20 comment | 10 complexity | 7934369a4985eec696dc2a4c3ea42753 MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  1. #!/usr/bin/env bash
  2. # Licensed to the Apache Software Foundation (ASF) under one or more
  3. # contributor license agreements. See the NOTICE file distributed with
  4. # this work for additional information regarding copyright ownership.
  5. # The ASF licenses this file to You under the Apache License, Version 2.0
  6. # (the "License"); you may not use this file except in compliance with
  7. # the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # The purpose of this script is to set warehouse's directories on HDFS
  17. DEFAULT_WAREHOUSE_DIR="/user/hive/warehouse"
  18. DEFAULT_TMP_DIR="/tmp"
  19. WAREHOUSE_DIR=${DEFAULT_WAREHOUSE_DIR}
  20. TMP_DIR=${DEFAULT_TMP_DIR}
  21. HELP=""
  22. while [ $# -gt 0 ]; do
  23. case "$1" in
  24. --warehouse-dir)
  25. shift
  26. WAREHOUSE_DIR=$1
  27. shift
  28. ;;
  29. --tmp-dir)
  30. shift
  31. TMP_DIR=$1
  32. shift
  33. ;;
  34. --help)
  35. HELP=_help
  36. shift
  37. ;;
  38. *)
  39. echo "Invalid parameter: $1"
  40. HELP=_help
  41. break
  42. ;;
  43. esac
  44. done
  45. if [ "$HELP" = "_help" ] ; then
  46. echo "Usage $0 [--warehouse-dir <Hive user>] [--tmp-dir <Tmp dir>]"
  47. echo "Default value of warehouse directory is: [$DEFAULT_WAREHOUSE_DIR]"
  48. echo "Default value of the temporary directory is: [$DEFAULT_TMP_DIR]"
  49. exit -1
  50. fi
  51. # check for hadoop in the path
  52. HADOOP_IN_PATH=`which hadoop 2>/dev/null`
  53. if [ -f ${HADOOP_IN_PATH} ]; then
  54. HADOOP_DIR=`dirname "$HADOOP_IN_PATH"`/..
  55. fi
  56. # HADOOP_HOME env variable overrides hadoop in the path
  57. HADOOP_HOME=${HADOOP_HOME:-$HADOOP_DIR}
  58. if [ "$HADOOP_HOME" == "" ]; then
  59. echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path";
  60. exit 4;
  61. fi
  62. HADOOP_EXEC=$HADOOP_HOME/bin/hadoop
  63. if [ ! -f ${HADOOP} ]; then
  64. echo "Cannot find hadoop installation: \$HADOOP_HOME must be set or hadoop must be in the path";
  65. exit 4;
  66. fi
  67. # Ensure /tmp exist
  68. $HADOOP_EXEC fs -test -d ${TMP_DIR} > /dev/null 2>&1
  69. if [ $? -ne 0 ]
  70. then
  71. echo "Creating directory [${TMP_DIR}]"
  72. $HADOOP_EXEC fs -mkdir ${TMP_DIR}
  73. fi
  74. echo "Setting writeable group rights for directory [${TMP_DIR}]"
  75. $HADOOP_EXEC fs -chmod g+w ${TMP_DIR}
  76. # Ensure warehouse dir exist
  77. $HADOOP_EXEC fs -test -d ${WAREHOUSE_DIR} > /dev/null 2>&1
  78. if [ $? -ne 0 ]
  79. then
  80. echo "Creating directory [${WAREHOUSE_DIR}]"
  81. $HADOOP_EXEC fs -mkdir ${WAREHOUSE_DIR}
  82. fi
  83. echo "Setting writeable group rights for directory [${WAREHOUSE_DIR}]"
  84. $HADOOP_EXEC fs -chmod g+w ${WAREHOUSE_DIR}
  85. echo "Initialization done."
  86. echo
  87. echo "Please, do not forget to set the following configuration properties in hive-site.xml:"
  88. echo "hive.metastore.warehouse.dir=${WAREHOUSE_DIR}"
  89. echo "hive.exec.scratchdir=${TMP_DIR}"
  90. exit 0