hadoop 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. function hadoop_usage()
  17. {
  18. echo "Usage: hadoop [--config confdir] COMMAND"
  19. echo " where COMMAND is one of:"
  20. echo " archive -archiveName NAME -p <parent path> <src>* <dest>"
  21. echo " create a Hadoop archive"
  22. echo " checknative [-a|-h] check native Hadoop and compression "
  23. echo " libraries availability"
  24. echo " classpath prints the class path needed to get the"
  25. echo " Hadoop jar and the required libraries"
  26. echo " credential interact with credential providers"
  27. echo " daemonlog get/set the log level for each daemon"
  28. echo " distch path:owner:group:permisson"
  29. echo " distributed metadata changer"
  30. echo " distcp <srcurl> <desturl> "
  31. echo " copy file or directories recursively"
  32. echo " fs run a generic filesystem user client"
  33. echo " jar <jar> run a jar file"
  34. echo " jnipath prints the java.library.path"
  35. echo " key manage keys via the KeyProvider"
  36. echo " version print the version"
  37. echo " or"
  38. echo " CLASSNAME run the class named CLASSNAME"
  39. echo ""
  40. echo "Most commands print help when invoked w/o parameters."
  41. }
  42. # This script runs the hadoop core commands.
  43. # let's locate libexec...
  44. if [[ -n "${HADOOP_PREFIX}" ]]; then
  45. DEFAULT_LIBEXEC_DIR="${HADOOP_PREFIX}/libexec"
  46. else
  47. this="${BASH_SOURCE-$0}"
  48. bin=$(cd -P -- "$(dirname -- "${this}")" >/dev/null && pwd -P)
  49. DEFAULT_LIBEXEC_DIR="${bin}/../libexec"
  50. fi
  51. HADOOP_LIBEXEC_DIR="${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}"
  52. # shellcheck disable=SC2034
  53. HADOOP_NEW_CONFIG=true
  54. if [[ -f "${HADOOP_LIBEXEC_DIR}/hadoop-config.sh" ]]; then
  55. . "${HADOOP_LIBEXEC_DIR}/hadoop-config.sh"
  56. else
  57. echo "ERROR: Cannot execute ${HADOOP_LIBEXEC_DIR}/hadoop-config.sh." 2>&1
  58. exit 1
  59. fi
  60. if [ $# = 0 ]; then
  61. hadoop_exit_with_usage 1
  62. fi
  63. COMMAND=$1
  64. shift
  65. case ${COMMAND} in
  66. balancer|datanode|dfs|dfsadmin|dfsgroups| \
  67. namenode|secondarynamenode|fsck|fetchdt|oiv| \
  68. portmap|nfs3)
  69. hadoop_error "WARNING: Use of this script to execute ${COMMAND} is deprecated."
  70. COMMAND=${COMMAND/dfsgroups/groups}
  71. hadoop_error "WARNING: Attempting to execute replacement \"hdfs ${COMMAND}\" instead."
  72. hadoop_error ""
  73. #try to locate hdfs and if present, delegate to it.
  74. if [[ -f "${HADOOP_HDFS_HOME}/bin/hdfs" ]]; then
  75. # shellcheck disable=SC2086
  76. exec "${HADOOP_HDFS_HOME}/bin/hdfs" \
  77. --config "${HADOOP_CONF_DIR}" "${COMMAND}" "$@"
  78. elif [[ -f "${HADOOP_PREFIX}/bin/hdfs" ]]; then
  79. # shellcheck disable=SC2086
  80. exec "${HADOOP_PREFIX}/bin/hdfs" \
  81. --config "${HADOOP_CONF_DIR}" "${COMMAND}" "$@"
  82. else
  83. hadoop_error "HADOOP_HDFS_HOME not found!"
  84. exit 1
  85. fi
  86. ;;
  87. #mapred commands for backwards compatibility
  88. pipes|job|queue|mrgroups|mradmin|jobtracker|tasktracker)
  89. hadoop_error "WARNING: Use of this script to execute ${COMMAND} is deprecated."
  90. COMMAND=${COMMAND/mrgroups/groups}
  91. hadoop_error "WARNING: Attempting to execute replacement \"mapred ${COMMAND}\" instead."
  92. hadoop_error ""
  93. #try to locate mapred and if present, delegate to it.
  94. if [[ -f "${HADOOP_MAPRED_HOME}/bin/mapred" ]]; then
  95. exec "${HADOOP_MAPRED_HOME}/bin/mapred" \
  96. --config "${HADOOP_CONF_DIR}" "${COMMAND}" "$@"
  97. elif [[ -f "${HADOOP_PREFIX}/bin/mapred" ]]; then
  98. exec "${HADOOP_PREFIX}/bin/mapred" \
  99. --config "${HADOOP_CONF_DIR}" "${COMMAND}" "$@"
  100. else
  101. hadoop_error "HADOOP_MAPRED_HOME not found!"
  102. exit 1
  103. fi
  104. ;;
  105. archive)
  106. CLASS=org.apache.hadoop.tools.HadoopArchives
  107. hadoop_debug "Injecting TOOL_PATH into CLASSPATH"
  108. hadoop_add_classpath "${TOOL_PATH}"
  109. ;;
  110. checknative)
  111. CLASS=org.apache.hadoop.util.NativeLibraryChecker
  112. ;;
  113. classpath)
  114. if [[ "$#" -eq 1 ]]; then
  115. CLASS=org.apache.hadoop.util.Classpath
  116. else
  117. hadoop_finalize
  118. echo "${CLASSPATH}"
  119. exit 0
  120. fi
  121. ;;
  122. credential)
  123. CLASS=org.apache.hadoop.security.alias.CredentialShell
  124. ;;
  125. daemonlog)
  126. CLASS=org.apache.hadoop.log.LogLevel
  127. ;;
  128. distch)
  129. CLASS=org.apache.hadoop.tools.DistCh
  130. hadoop_debug "Injecting TOOL_PATH into CLASSPATH"
  131. hadoop_add_classpath "${TOOL_PATH}"
  132. ;;
  133. distcp)
  134. CLASS=org.apache.hadoop.tools.DistCp
  135. hadoop_debug "Injecting TOOL_PATH into CLASSPATH"
  136. hadoop_add_classpath "${TOOL_PATH}"
  137. ;;
  138. fs)
  139. CLASS=org.apache.hadoop.fs.FsShell
  140. ;;
  141. jar)
  142. CLASS=org.apache.hadoop.util.RunJar
  143. ;;
  144. jnipath)
  145. hadoop_finalize
  146. echo "${JAVA_LIBRARY_PATH}"
  147. exit 0
  148. ;;
  149. key)
  150. CLASS=org.apache.hadoop.crypto.key.KeyShell
  151. ;;
  152. version)
  153. CLASS=org.apache.hadoop.util.VersionInfo
  154. ;;
  155. -*|hdfs)
  156. hadoop_exit_with_usage 1
  157. ;;
  158. *)
  159. CLASS="${COMMAND}"
  160. ;;
  161. esac
  162. # Always respect HADOOP_OPTS and HADOOP_CLIENT_OPTS
  163. hadoop_debug "Appending HADOOP_CLIENT_OPTS onto HADOOP_OPTS"
  164. HADOOP_OPTS="${HADOOP_OPTS} ${HADOOP_CLIENT_OPTS}"
  165. hadoop_add_param HADOOP_OPTS Xmx "${JAVA_HEAP_MAX}"
  166. hadoop_finalize
  167. hadoop_java_exec "${COMMAND}" "${CLASS}" "$@"