1
0

hadoop-config.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 [[ -f "${HADOOP_LIBEXEC_DIR}/hadoop-functions.sh" ]]; then
  49. . "${HADOOP_LIBEXEC_DIR}/hadoop-functions.sh"
  50. else
  51. echo "ERROR: Unable to exec ${HADOOP_LIBEXEC_DIR}/hadoop-functions.sh." 1>&2
  52. exit 1
  53. fi
  54. # allow overrides of the above and pre-defines of the below
  55. if [[ -f "${HADOOP_LIBEXEC_DIR}/hadoop-layout.sh" ]]; then
  56. . "${HADOOP_LIBEXEC_DIR}/hadoop-layout.sh"
  57. fi
  58. #
  59. # IMPORTANT! We are not executing user provided code yet!
  60. #
  61. # Let's go! Base definitions so we can move forward
  62. hadoop_bootstrap_init
  63. # let's find our conf.
  64. #
  65. # first, check and process params passed to us
  66. # we process this in-line so that we can directly modify $@
  67. # if something downstream is processing that directly,
  68. # we need to make sure our params have been ripped out
  69. # note that we do many of them here for various utilities.
  70. # this provides consistency and forces a more consistent
  71. # user experience
  72. # save these off in case our caller needs them
  73. # shellcheck disable=SC2034
  74. HADOOP_USER_PARAMS="$@"
  75. HADOOP_DAEMON_MODE="default"
  76. while [[ -z "${_hadoop_common_done}" ]]; do
  77. case $1 in
  78. --buildpaths)
  79. # shellcheck disable=SC2034
  80. HADOOP_ENABLE_BUILD_PATHS=true
  81. shift
  82. ;;
  83. --config)
  84. shift
  85. confdir=$1
  86. shift
  87. if [[ -d "${confdir}" ]]; then
  88. # shellcheck disable=SC2034
  89. YARN_CONF_DIR="${confdir}"
  90. # shellcheck disable=SC2034
  91. HADOOP_CONF_DIR="${confdir}"
  92. elif [[ -z "${confdir}" ]]; then
  93. hadoop_error "ERROR: No parameter provided for --config "
  94. hadoop_exit_with_usage 1
  95. else
  96. hadoop_error "ERROR: Cannot find configuration directory \"${confdir}\""
  97. hadoop_exit_with_usage 1
  98. fi
  99. ;;
  100. --daemon)
  101. shift
  102. HADOOP_DAEMON_MODE=$1
  103. shift
  104. if [[ -z "${HADOOP_DAEMON_MODE}" || \
  105. ! "${HADOOP_DAEMON_MODE}" =~ ^st(art|op|atus)$ ]]; then
  106. hadoop_error "ERROR: --daemon must be followed by either \"start\", \"stop\", or \"status\"."
  107. hadoop_exit_with_usage 1
  108. fi
  109. ;;
  110. --help|-help|-h|help|--h|--\?|-\?|\?)
  111. hadoop_exit_with_usage 0
  112. ;;
  113. --hostnames)
  114. shift
  115. # shellcheck disable=SC2034
  116. HADOOP_SLAVE_NAMES="$1"
  117. shift
  118. ;;
  119. --hosts)
  120. shift
  121. hadoop_populate_slaves_file "$1"
  122. shift
  123. ;;
  124. *)
  125. _hadoop_common_done=true
  126. ;;
  127. esac
  128. done
  129. hadoop_find_confdir
  130. hadoop_exec_hadoopenv
  131. #
  132. # IMPORTANT! User provided code is now available!
  133. #
  134. # do all the OS-specific startup bits here
  135. # this allows us to get a decent JAVA_HOME,
  136. # call crle for LD_LIBRARY_PATH, etc.
  137. hadoop_os_tricks
  138. hadoop_java_setup
  139. hadoop_basic_init
  140. # inject any sub-project overrides, defaults, etc.
  141. if declare -F hadoop_subproject_init >/dev/null ; then
  142. hadoop_subproject_init
  143. fi
  144. # get the native libs in there pretty quick
  145. hadoop_add_javalibpath "${HADOOP_PREFIX}/build/native"
  146. hadoop_add_javalibpath "${HADOOP_PREFIX}/${HADOOP_COMMON_LIB_NATIVE_DIR}"
  147. # get the basic java class path for these subprojects
  148. # in as quickly as possible since other stuff
  149. # will definitely depend upon it.
  150. #
  151. # at some point, this will get replaced with something pluggable
  152. # so that these functions can sit in their projects rather than
  153. # common
  154. #
  155. for i in common hdfs yarn mapred
  156. do
  157. hadoop_add_to_classpath_$i
  158. done
  159. #
  160. # backwards compatibility. new stuff should
  161. # call this when they are ready
  162. #
  163. if [[ -z "${HADOOP_NEW_CONFIG}" ]]; then
  164. hadoop_finalize
  165. fi