update-mapred-env.sh 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. # This script configures mapred-env.sh and symlinkis directories for
  17. # relocating RPM locations.
  18. usage() {
  19. echo "
  20. usage: $0 <parameters>
  21. Required parameters:
  22. --prefix=PREFIX path to install into
  23. Optional parameters:
  24. --arch=i386 OS Architecture
  25. --bin-dir=PREFIX/bin Executable directory
  26. --conf-dir=/etc/hadoop Configuration directory
  27. --log-dir=/var/log/hadoop Log directory
  28. --pid-dir=/var/run PID file location
  29. --sbin-dir=PREFIX/sbin System executable directory
  30. "
  31. exit 1
  32. }
  33. template_generator() {
  34. cat $1 |
  35. while read line ; do
  36. while [[ "$line" =~ '(\$\{[a-zA-Z_][a-zA-Z_0-9]*\})' ]] ; do
  37. LHS=${BASH_REMATCH[1]}
  38. RHS="$(eval echo "\"$LHS\"")"
  39. line=${line//$LHS/$RHS}
  40. done
  41. echo $line >> $2
  42. done
  43. }
  44. OPTS=$(getopt \
  45. -n $0 \
  46. -o '' \
  47. -l 'arch:' \
  48. -l 'prefix:' \
  49. -l 'bin-dir:' \
  50. -l 'conf-dir:' \
  51. -l 'lib-dir:' \
  52. -l 'log-dir:' \
  53. -l 'pid-dir:' \
  54. -l 'sbin-dir:' \
  55. -l 'uninstall' \
  56. -- "$@")
  57. if [ $? != 0 ] ; then
  58. usage
  59. fi
  60. eval set -- "${OPTS}"
  61. while true ; do
  62. case "$1" in
  63. --arch)
  64. ARCH=$2 ; shift 2
  65. ;;
  66. --prefix)
  67. PREFIX=$2 ; shift 2
  68. ;;
  69. --bin-dir)
  70. BIN_DIR=$2 ; shift 2
  71. ;;
  72. --log-dir)
  73. LOG_DIR=$2 ; shift 2
  74. ;;
  75. --lib-dir)
  76. LIB_DIR=$2 ; shift 2
  77. ;;
  78. --conf-dir)
  79. CONF_DIR=$2 ; shift 2
  80. ;;
  81. --pid-dir)
  82. PID_DIR=$2 ; shift 2
  83. ;;
  84. --sbin-dir)
  85. SBIN_DIR=$2 ; shift 2
  86. ;;
  87. --uninstall)
  88. UNINSTALL=1; shift
  89. ;;
  90. --)
  91. shift ; break
  92. ;;
  93. *)
  94. echo "Unknown option: $1"
  95. usage
  96. exit 1
  97. ;;
  98. esac
  99. done
  100. for var in PREFIX; do
  101. if [ -z "$(eval "echo \$$var")" ]; then
  102. echo Missing param: $var
  103. usage
  104. fi
  105. done
  106. ARCH=${ARCH:-i386}
  107. BIN_DIR=${BIN_DIR:-$PREFIX/bin}
  108. CONF_DIR=${CONF_DIR:-$PREFIX/etc/hadoop}
  109. LIB_DIR=${LIB_DIR:-$PREFIX/lib}
  110. LOG_DIR=${LOG_DIR:-$PREFIX/var/log}
  111. PID_DIR=${PID_DIR:-$PREFIX/var/run}
  112. SBIN_DIR=${SBIN_DIR:-$PREFIX/sbin}
  113. UNINSTALL=${UNINSTALL:-0}
  114. if [ "${ARCH}" != "i386" ]; then
  115. LIB_DIR=${LIB_DIR}64
  116. fi
  117. if [ "${UNINSTALL}" -ne "1" ]; then
  118. mkdir -p ${LOG_DIR}
  119. chown mapred:hadoop ${LOG_DIR}
  120. chmod 755 ${LOG_DIR}
  121. if [ ! -d ${PID_DIR} ]; then
  122. mkdir -p ${PID_DIR}
  123. chown root:hadoop ${PID_DIR}
  124. chmod 775 ${PID_DIR}
  125. fi
  126. fi