hadoop-config.sh 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. #
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one or more
  4. # contributor license agreements. See the NOTICE file distributed with
  5. # this work for additional information regarding copyright ownership.
  6. # The ASF licenses this file to You under the Apache License, Version 2.0
  7. # (the "License"); you may not use this file except in compliance with
  8. # 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. ####
  18. # IMPORTANT
  19. ####
  20. ## The hadoop-config.sh tends to get executed by non-Hadoop scripts.
  21. ## Those parts expect this script to parse/manipulate $@. In order
  22. ## to maintain backward compatibility, this means a surprising
  23. ## lack of functions for bits that would be much better off in
  24. ## a function.
  25. ##
  26. ## In other words, yes, there is some bad things happen here and
  27. ## unless we break the rest of the ecosystem, we can't change it. :(
  28. # included in all the hadoop scripts with source command
  29. # should not be executable directly
  30. # also should not be passed any arguments, since we need original $*
  31. #
  32. # after doing more config, caller should also exec finalize
  33. # function to finish last minute/default configs for
  34. # settings that might be different between daemons & interactive
  35. # you must be this high to ride the ride
  36. if [[ -z "${BASH_VERSINFO}" ]] || [[ "${BASH_VERSINFO}" -lt 3 ]]; then
  37. echo "Hadoop requires bash v3 or better. Sorry."
  38. exit 1
  39. fi
  40. # In order to get partially bootstrapped, we need to figure out where
  41. # we are located. Chances are good that our caller has already done
  42. # this work for us, but just in case...
  43. if [[ -z "${HADOOP_LIBEXEC_DIR}" ]]; then
  44. _hadoop_common_this="${BASH_SOURCE-$0}"
  45. HADOOP_LIBEXEC_DIR=$(cd -P -- "$(dirname -- "${_hadoop_common_this}")" >/dev/null && pwd -P)
  46. fi
  47. # get our functions defined for usage later
  48. if [[ -n "${HADOOP_COMMON_HOME}" ]] &&
  49. [[ -e "${HADOOP_COMMON_HOME}/libexec/hadoop-functions.sh" ]]; then
  50. . "${HADOOP_COMMON_HOME}/libexec/hadoop-functions.sh"
  51. elif [[ -e "${HADOOP_LIBEXEC_DIR}/hadoop-functions.sh" ]]; then
  52. . "${HADOOP_LIBEXEC_DIR}/hadoop-functions.sh"
  53. else
  54. echo "ERROR: Unable to exec ${HADOOP_LIBEXEC_DIR}/hadoop-functions.sh." 1>&2
  55. exit 1
  56. fi
  57. # allow overrides of the above and pre-defines of the below
  58. if [[ -n "${HADOOP_COMMON_HOME}" ]] &&
  59. [[ -e "${HADOOP_COMMON_HOME}/libexec/hadoop-layout.sh" ]]; then
  60. . "${HADOOP_COMMON_HOME}/libexec/hadoop-layout.sh"
  61. elif [[ -e "${HADOOP_LIBEXEC_DIR}/hadoop-layout.sh" ]]; then
  62. . "${HADOOP_LIBEXEC_DIR}/hadoop-layout.sh"
  63. fi
  64. #
  65. # IMPORTANT! We are not executing user provided code yet!
  66. #
  67. # Let's go! Base definitions so we can move forward
  68. hadoop_bootstrap_init
  69. # let's find our conf.
  70. #
  71. # first, check and process params passed to us
  72. # we process this in-line so that we can directly modify $@
  73. # if something downstream is processing that directly,
  74. # we need to make sure our params have been ripped out
  75. # note that we do many of them here for various utilities.
  76. # this provides consistency and forces a more consistent
  77. # user experience
  78. # save these off in case our caller needs them
  79. # shellcheck disable=SC2034
  80. HADOOP_USER_PARAMS="$@"
  81. HADOOP_DAEMON_MODE="default"
  82. while [[ -z "${_hadoop_common_done}" ]]; do
  83. case $1 in
  84. --buildpaths)
  85. # shellcheck disable=SC2034
  86. HADOOP_ENABLE_BUILD_PATHS=true
  87. shift
  88. ;;
  89. --config)
  90. shift
  91. confdir=$1
  92. shift
  93. if [[ -d "${confdir}" ]]; then
  94. # shellcheck disable=SC2034
  95. YARN_CONF_DIR="${confdir}"
  96. # shellcheck disable=SC2034
  97. HADOOP_CONF_DIR="${confdir}"
  98. elif [[ -z "${confdir}" ]]; then
  99. hadoop_error "ERROR: No parameter provided for --config "
  100. hadoop_exit_with_usage 1
  101. else
  102. hadoop_error "ERROR: Cannot find configuration directory \"${confdir}\""
  103. hadoop_exit_with_usage 1
  104. fi
  105. ;;
  106. --daemon)
  107. shift
  108. HADOOP_DAEMON_MODE=$1
  109. shift
  110. if [[ -z "${HADOOP_DAEMON_MODE}" || \
  111. ! "${HADOOP_DAEMON_MODE}" =~ ^st(art|op|atus)$ ]]; then
  112. hadoop_error "ERROR: --daemon must be followed by either \"start\", \"stop\", or \"status\"."
  113. hadoop_exit_with_usage 1
  114. fi
  115. ;;
  116. --debug)
  117. shift
  118. # shellcheck disable=SC2034
  119. HADOOP_SHELL_SCRIPT_DEBUG=true
  120. ;;
  121. --help|-help|-h|help|--h|--\?|-\?|\?)
  122. hadoop_exit_with_usage 0
  123. ;;
  124. --hostnames)
  125. shift
  126. # shellcheck disable=SC2034
  127. HADOOP_SLAVE_NAMES="$1"
  128. shift
  129. ;;
  130. --hosts)
  131. shift
  132. hadoop_populate_slaves_file "$1"
  133. shift
  134. ;;
  135. *)
  136. _hadoop_common_done=true
  137. ;;
  138. esac
  139. done
  140. hadoop_find_confdir
  141. hadoop_exec_hadoopenv
  142. hadoop_exec_userfuncs
  143. #
  144. # IMPORTANT! User provided code is now available!
  145. #
  146. # do all the OS-specific startup bits here
  147. # this allows us to get a decent JAVA_HOME,
  148. # call crle for LD_LIBRARY_PATH, etc.
  149. hadoop_os_tricks
  150. hadoop_java_setup
  151. hadoop_basic_init
  152. # inject any sub-project overrides, defaults, etc.
  153. if declare -F hadoop_subproject_init >/dev/null ; then
  154. hadoop_subproject_init
  155. fi
  156. # get the native libs in there pretty quick
  157. hadoop_add_javalibpath "${HADOOP_PREFIX}/build/native"
  158. hadoop_add_javalibpath "${HADOOP_PREFIX}/${HADOOP_COMMON_LIB_NATIVE_DIR}"
  159. # get the basic java class path for these subprojects
  160. # in as quickly as possible since other stuff
  161. # will definitely depend upon it.
  162. #
  163. # at some point, this will get replaced with something pluggable
  164. # so that these functions can sit in their projects rather than
  165. # common
  166. #
  167. for i in common hdfs yarn mapred
  168. do
  169. hadoop_add_to_classpath_$i
  170. done
  171. #
  172. # backwards compatibility. new stuff should
  173. # call this when they are ready
  174. #
  175. if [[ -z "${HADOOP_NEW_CONFIG}" ]]; then
  176. hadoop_finalize
  177. fi