hadoop 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 runs the hadoop core commands.
  17. bin=`which $0`
  18. bin=`dirname ${bin}`
  19. bin=`cd "$bin"; pwd`
  20. DEFAULT_LIBEXEC_DIR="$bin"/../libexec
  21. if [ -n "$HADOOP_HOME" ]; then
  22. DEFAULT_LIBEXEC_DIR="$HADOOP_HOME"/libexec
  23. fi
  24. HADOOP_LIBEXEC_DIR=${HADOOP_LIBEXEC_DIR:-$DEFAULT_LIBEXEC_DIR}
  25. . $HADOOP_LIBEXEC_DIR/hadoop-config.sh
  26. function print_usage(){
  27. echo "Usage: hadoop [--config confdir] COMMAND"
  28. echo " where COMMAND is one of:"
  29. echo " fs run a generic filesystem user client"
  30. echo " version print the version"
  31. echo " jar <jar> run a jar file"
  32. echo " checknative [-a|-h] check native hadoop and compression libraries availability"
  33. echo " distcp <srcurl> <desturl> copy file or directories recursively"
  34. echo " archive -archiveName NAME -p <parent path> <src>* <dest> create a hadoop archive"
  35. echo " classpath prints the class path needed to get the"
  36. echo " credential interact with credential providers"
  37. echo " Hadoop jar and the required libraries"
  38. echo " daemonlog get/set the log level for each daemon"
  39. echo " trace view and modify Hadoop tracing settings"
  40. echo " or"
  41. echo " CLASSNAME run the class named CLASSNAME"
  42. echo ""
  43. echo "Most commands print help when invoked w/o parameters."
  44. }
  45. if [ $# = 0 ]; then
  46. print_usage
  47. exit
  48. fi
  49. COMMAND=$1
  50. case $COMMAND in
  51. # usage flags
  52. --help|-help|-h)
  53. print_usage
  54. exit
  55. ;;
  56. #hdfs commands
  57. namenode|secondarynamenode|datanode|dfs|dfsadmin|fsck|balancer|fetchdt|oiv|dfsgroups|portmap|nfs3)
  58. echo "DEPRECATED: Use of this script to execute hdfs command is deprecated." 1>&2
  59. echo "Instead use the hdfs command for it." 1>&2
  60. echo "" 1>&2
  61. #try to locate hdfs and if present, delegate to it.
  62. shift
  63. if [ -f "${HADOOP_HDFS_HOME}"/bin/hdfs ]; then
  64. exec "${HADOOP_HDFS_HOME}"/bin/hdfs ${COMMAND/dfsgroups/groups} "$@"
  65. elif [ -f "${HADOOP_PREFIX}"/bin/hdfs ]; then
  66. exec "${HADOOP_PREFIX}"/bin/hdfs ${COMMAND/dfsgroups/groups} "$@"
  67. else
  68. echo "HADOOP_HDFS_HOME not found!"
  69. exit 1
  70. fi
  71. ;;
  72. #mapred commands for backwards compatibility
  73. pipes|job|queue|mrgroups|mradmin|jobtracker|tasktracker)
  74. echo "DEPRECATED: Use of this script to execute mapred command is deprecated." 1>&2
  75. echo "Instead use the mapred command for it." 1>&2
  76. echo "" 1>&2
  77. #try to locate mapred and if present, delegate to it.
  78. shift
  79. if [ -f "${HADOOP_MAPRED_HOME}"/bin/mapred ]; then
  80. exec "${HADOOP_MAPRED_HOME}"/bin/mapred ${COMMAND/mrgroups/groups} "$@"
  81. elif [ -f "${HADOOP_PREFIX}"/bin/mapred ]; then
  82. exec "${HADOOP_PREFIX}"/bin/mapred ${COMMAND/mrgroups/groups} "$@"
  83. else
  84. echo "HADOOP_MAPRED_HOME not found!"
  85. exit 1
  86. fi
  87. ;;
  88. #core commands
  89. *)
  90. # the core commands
  91. if [ "$COMMAND" = "fs" ] ; then
  92. CLASS=org.apache.hadoop.fs.FsShell
  93. elif [ "$COMMAND" = "version" ] ; then
  94. CLASS=org.apache.hadoop.util.VersionInfo
  95. elif [ "$COMMAND" = "jar" ] ; then
  96. CLASS=org.apache.hadoop.util.RunJar
  97. elif [ "$COMMAND" = "key" ] ; then
  98. CLASS=org.apache.hadoop.crypto.key.KeyShell
  99. elif [ "$COMMAND" = "checknative" ] ; then
  100. CLASS=org.apache.hadoop.util.NativeLibraryChecker
  101. elif [ "$COMMAND" = "distcp" ] ; then
  102. CLASS=org.apache.hadoop.tools.DistCp
  103. CLASSPATH=${CLASSPATH}:${TOOL_PATH}
  104. elif [ "$COMMAND" = "daemonlog" ] ; then
  105. CLASS=org.apache.hadoop.log.LogLevel
  106. elif [ "$COMMAND" = "archive" ] ; then
  107. CLASS=org.apache.hadoop.tools.HadoopArchives
  108. CLASSPATH=${CLASSPATH}:${TOOL_PATH}
  109. elif [ "$COMMAND" = "credential" ] ; then
  110. CLASS=org.apache.hadoop.security.alias.CredentialShell
  111. elif [ "$COMMAND" = "trace" ] ; then
  112. CLASS=org.apache.hadoop.tracing.TraceAdmin
  113. elif [ "$COMMAND" = "classpath" ] ; then
  114. if [ "$#" -eq 1 ]; then
  115. # No need to bother starting up a JVM for this simple case.
  116. echo $CLASSPATH
  117. exit
  118. else
  119. CLASS=org.apache.hadoop.util.Classpath
  120. fi
  121. elif [[ "$COMMAND" = -* ]] ; then
  122. # class and package names cannot begin with a -
  123. echo "Error: No command named \`$COMMAND' was found. Perhaps you meant \`hadoop ${COMMAND#-}'"
  124. exit 1
  125. else
  126. CLASS=$COMMAND
  127. fi
  128. shift
  129. # Always respect HADOOP_OPTS and HADOOP_CLIENT_OPTS
  130. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  131. #make sure security appender is turned off
  132. HADOOP_OPTS="$HADOOP_OPTS -Dhadoop.security.logger=${HADOOP_SECURITY_LOGGER:-INFO,NullAppender}"
  133. export CLASSPATH=$CLASSPATH
  134. exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@"
  135. ;;
  136. esac