PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/release-0.0.0-rc0/scripts/hcat_server_install.sh

#
Shell | 146 lines | 94 code | 24 blank | 28 comment | 34 complexity | c9f4b6f5a582e45057f84e7936957ffb MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, JSON, CPL-1.0
  1. #!/bin/sh
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF 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. # This script assumes that it is being run from the top level directory of the
  18. # HCatalog distribution tarball
  19. function usage() {
  20. echo "Usage: $0 -r root -d dbroot -h hadoop_home -p server_port"
  21. echo " root is the directory where you like to install the HCatalog server"
  22. echo " /usr/local/hcat is suggested."
  23. echo " dbroot is the directory where your mysql connector jar is located."
  24. echo " hadoop_home is the directory of your Hadoop installation."
  25. echo " server_port is the listening port of the HCatalog server"
  26. echo " All paths must be absolute"
  27. }
  28. dir_check=`head -1 NOTICE.txt`
  29. if [ "${dir_check}" != "Apache HCatalog" ] ; then
  30. echo "This script must be run in the top level directory of your HCatalog" \
  31. "distribution."
  32. exit 1
  33. fi
  34. root="unknown"
  35. dbroot="unknown"
  36. hadoop_home="unknown"
  37. server_port="9080"
  38. while [ "${1}x" != "x" ] ; do
  39. if [ $1 == "-r" ] || [ $1 == "--root" ] ; then
  40. shift
  41. root=$1
  42. shift
  43. elif [ $1 == "-d" ] || [ $1 == "--dbroot" ] ; then
  44. shift
  45. dbroot=$1
  46. shift
  47. elif [ $1 == "-h" ] || [ $1 == "--hadoop" ] ; then
  48. shift
  49. hadoop_home=$1
  50. shift
  51. elif [ $1 == "-p" ] || [ $1 == "--port" ] ; then
  52. shift
  53. server_port=$1
  54. shift
  55. else
  56. echo "Unknown option $1"
  57. shift
  58. fi
  59. done
  60. for var in $root $dbroot $hadoop_home ; do
  61. if [ $var == "unknown" ] ; then
  62. usage
  63. exit 1
  64. fi
  65. done
  66. # Make sure root and dbroot are absolute paths
  67. for var in $root $dbroot $hadoop_home ; do
  68. if [ ${var:0:1} != "/" ] ; then
  69. usage
  70. exit 1
  71. fi
  72. done
  73. # Make sure root is writable and has the necessary directories
  74. root_owner=`ls -ld $root | awk '{print $3}'`
  75. if [ $root_owner != `whoami` ] ; then
  76. echo "You must run this as the user that will run HCatalog and that user" \
  77. "must own the root directory."
  78. exit 1
  79. fi
  80. root_perms=`ls -ld $root | awk '{print $1}'`
  81. if [ ${root_perms:0:4} != "drwx" ] ; then
  82. echo "Your root directory must be readable, writable, and executable by" \
  83. "its owner."
  84. exit 1
  85. fi
  86. # Check that the required Mysql driver is in the dbroot
  87. mysql_jar=`ls ${dbroot}/mysql-connector-java-*.jar 2>/dev/null | grep mysql-connector-java`
  88. if [ "${mysql_jar}x" == "x" ] ; then
  89. echo "The required jar file mysql-connector-java-version.jar is not in " \
  90. "$dbroot or is not readable"
  91. exit 1
  92. fi
  93. # Create the needed directories in root
  94. for dir in var conf var/log bin lib ; do
  95. if [ ! -d $root/$dir ] ; then
  96. mkdir $root/$dir
  97. fi
  98. done
  99. # Move files into the appropriate directories
  100. for dir in bin conf lib ; do
  101. for file in ./$dir/* ; do
  102. cp -R $file $root/$dir
  103. done
  104. done
  105. # Put the start and stop scripts into bin
  106. for file in hcat_server_start.sh hcat_server_stop.sh ; do
  107. cp scripts/$file $root/bin
  108. done
  109. # Move the proto-hive-site.xml to hive-site.xml
  110. cp $root/conf/proto-hive-site.xml $root/conf/hive-site.xml
  111. # Set permissions on hive-site.xml to 700, since it will contain the password to the
  112. # database
  113. chmod 700 $root/conf/hive-site.xml
  114. # Write out an environment file so that the start file can use it later
  115. cat > $root/conf/hcat-env.sh <<!!
  116. ROOT=$root
  117. DBROOT=$dbroot
  118. USER=`whoami`
  119. HADOOP_HOME=$hadoop_home
  120. export METASTORE_PORT=$server_port
  121. !!
  122. echo "Installation successful"