mapred 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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: mapred [--config confdir] [--daemon (start|stop|status)]"
  19. echo " [--loglevel loglevel] COMMAND"
  20. echo " where COMMAND is one of:"
  21. echo " archive -archiveName NAME -p <parent path> <src>* <dest> create a hadoop archive"
  22. echo " classpath prints the class path needed for running"
  23. echo " mapreduce subcommands"
  24. echo " distcp <srcurl> <desturl> copy file or directories recursively"
  25. echo " job manipulate MapReduce jobs"
  26. echo " historyserver run job history servers as a standalone daemon"
  27. echo " pipes run a Pipes job"
  28. echo " queue get information regarding JobQueues"
  29. echo " sampler sampler"
  30. echo " version print the version"
  31. echo ""
  32. echo "Most commands print help when invoked w/o parameters."
  33. }
  34. this="${BASH_SOURCE-$0}"
  35. bin=$(cd -P -- "$(dirname -- "${this}")" >/dev/null && pwd -P)
  36. # let's locate libexec...
  37. if [[ -n "${HADOOP_PREFIX}" ]]; then
  38. DEFAULT_LIBEXEC_DIR="${HADOOP_PREFIX}/libexec"
  39. else
  40. DEFAULT_LIBEXEC_DIR="${bin}/../libexec"
  41. fi
  42. HADOOP_LIBEXEC_DIR="${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}"
  43. # shellcheck disable=SC2034
  44. HADOOP_NEW_CONFIG=true
  45. if [[ -f "${HADOOP_LIBEXEC_DIR}/mapred-config.sh" ]]; then
  46. . "${HADOOP_LIBEXEC_DIR}/mapred-config.sh"
  47. else
  48. echo "ERROR: Cannot execute ${HADOOP_LIBEXEC_DIR}/mapred-config.sh." 2>&1
  49. exit 1
  50. fi
  51. if [ $# = 0 ]; then
  52. hadoop_exit_with_usage 1
  53. fi
  54. COMMAND=$1
  55. shift
  56. case ${COMMAND} in
  57. mradmin|jobtracker|tasktracker|groups)
  58. hadoop_error "Sorry, the ${COMMAND} command is no longer supported."
  59. hadoop_error "You may find similar functionality with the \"yarn\" shell command."
  60. hadoop_exit_with_usage 1
  61. ;;
  62. archive)
  63. CLASS=org.apache.hadoop.tools.HadoopArchives
  64. hadoop_debug "Injecting TOOL_PATH into CLASSPATH"
  65. hadoop_add_classpath "${TOOL_PATH}"
  66. hadoop_debug "Appending HADOOP_CLIENT_OPTS onto HADOOP_OPTS"
  67. HADOOP_OPTS="${HADOOP_OPTS} ${HADOOP_CLIENT_OPTS}"
  68. ;;
  69. classpath)
  70. hadoop_finalize
  71. echo "${CLASSPATH}"
  72. exit 0
  73. ;;
  74. distcp)
  75. CLASS=org.apache.hadoop.tools.DistCp
  76. hadoop_debug "Injecting TOOL_PATH into CLASSPATH"
  77. hadoop_add_classpath "${TOOL_PATH}"
  78. hadoop_debug "Appending HADOOP_CLIENT_OPTS onto HADOOP_OPTS"
  79. HADOOP_OPTS="${HADOOP_OPTS} ${HADOOP_CLIENT_OPTS}"
  80. ;;
  81. historyserver)
  82. daemon="true"
  83. CLASS=org.apache.hadoop.mapreduce.v2.hs.JobHistoryServer
  84. hadoop_debug "Appending HADOOP_JOB_HISTORYSERVER_OPTS onto HADOOP_OPTS"
  85. HADOOP_OPTS="${HADOOP_OPTS} ${HADOOP_JOB_HISTORYSERVER_OPTS}"
  86. if [ -n "${HADOOP_JOB_HISTORYSERVER_HEAPSIZE}" ]; then
  87. JAVA_HEAP_MAX="-Xmx${HADOOP_JOB_HISTORYSERVER_HEAPSIZE}m"
  88. fi
  89. HADOOP_DAEMON_ROOT_LOGGER=${HADOOP_JHS_LOGGER:-$HADOOP_DAEMON_ROOT_LOGGER}
  90. ;;
  91. job)
  92. CLASS=org.apache.hadoop.mapred.JobClient
  93. ;;
  94. pipes)
  95. CLASS=org.apache.hadoop.mapred.pipes.Submitter
  96. hadoop_debug "Appending HADOOP_CLIENT_OPTS onto HADOOP_OPTS"
  97. HADOOP_OPTS="${HADOOP_OPTS} ${HADOOP_CLIENT_OPTS}"
  98. ;;
  99. queue)
  100. CLASS=org.apache.hadoop.mapred.JobQueueClient
  101. ;;
  102. sampler)
  103. CLASS=org.apache.hadoop.mapred.lib.InputSampler
  104. hadoop_debug "Appending HADOOP_CLIENT_OPTS onto HADOOP_OPTS"
  105. HADOOP_OPTS="${HADOOP_OPTS} ${HADOOP_CLIENT_OPTS}"
  106. ;;
  107. version)
  108. CLASS=org.apache.hadoop.util.VersionInfo
  109. hadoop_debug "Appending HADOOP_CLIENT_OPTS onto HADOOP_OPTS"
  110. HADOOP_OPTS="${HADOOP_OPTS} ${HADOOP_CLIENT_OPTS}"
  111. ;;
  112. *)
  113. CLASS="${COMMAND}"
  114. if ! hadoop_validate_classname "${CLASS}"; then
  115. hadoop_exit_with_usage 1
  116. fi
  117. ;;
  118. esac
  119. daemon_outfile="${HADOOP_LOG_DIR}/hadoop-${HADOOP_IDENT_STRING}-${COMMAND}-${HOSTNAME}.out"
  120. daemon_pidfile="${HADOOP_PID_DIR}/hadoop-${HADOOP_IDENT_STRING}-${COMMAND}.pid"
  121. if [[ "${HADOOP_DAEMON_MODE}" != "default" ]]; then
  122. # shellcheck disable=SC2034
  123. HADOOP_ROOT_LOGGER="${HADOOP_DAEMON_ROOT_LOGGER}"
  124. hadoop_add_param HADOOP_OPTS mapred.jobsummary.logger "-Dmapred.jobsummary.logger=${HADOOP_ROOT_LOGGER}"
  125. # shellcheck disable=SC2034
  126. HADOOP_LOGFILE="hadoop-${HADOOP_IDENT_STRING}-${COMMAND}-${HOSTNAME}.log"
  127. fi
  128. hadoop_add_param HADOOP_OPTS Xmx "${JAVA_HEAP_MAX}"
  129. hadoop_finalize
  130. if [[ -n "${daemon}" ]]; then
  131. if [[ -n "${secure_service}" ]]; then
  132. hadoop_secure_daemon_handler "${HADOOP_DAEMON_MODE}" "${COMMAND}"\
  133. "${CLASS}" "${daemon_pidfile}" "${daemon_outfile}" \
  134. "${priv_pidfile}" "${priv_outfile}" "${priv_errfile}" "$@"
  135. else
  136. hadoop_daemon_handler "${HADOOP_DAEMON_MODE}" "${COMMAND}" "${CLASS}" \
  137. "${daemon_pidfile}" "${daemon_outfile}" "$@"
  138. fi
  139. exit $?
  140. else
  141. hadoop_java_exec "${COMMAND}" "${CLASS}" "$@"
  142. fi