hadoop 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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=`dirname "$0"`
  18. bin=`cd "$bin"; pwd`
  19. . "$bin"/hadoop-config.sh
  20. function print_usage(){
  21. echo "Usage: hadoop [--config confdir] COMMAND"
  22. echo " where COMMAND is one of:"
  23. echo " fs run a generic filesystem user client"
  24. echo " version print the version"
  25. echo " jar <jar> run a jar file"
  26. echo " distcp <srcurl> <desturl> copy file or directories recursively"
  27. echo " archive -archiveName NAME -p <parent path> <src>* <dest> create a hadoop archive"
  28. echo " classpath prints the class path needed to get the"
  29. echo " Hadoop jar and the required libraries"
  30. echo " daemonlog get/set the log level for each daemon"
  31. echo " or"
  32. echo " CLASSNAME run the class named CLASSNAME"
  33. echo ""
  34. echo "Most commands print help when invoked w/o parameters."
  35. }
  36. if [ $# = 0 ]; then
  37. print_usage
  38. exit
  39. fi
  40. COMMAND=$1
  41. case $COMMAND in
  42. #hdfs commands
  43. namenode|secondarynamenode|datanode|dfs|dfsadmin|fsck|balancer)
  44. echo "DEPRECATED: Use of this script to execute hdfs command is deprecated."
  45. echo "Instead use the hdfs command for it."
  46. echo ""
  47. #try to locate hdfs and if present, delegate to it.
  48. if [ -f "${HADOOP_HDFS_HOME}"/bin/hdfs ]; then
  49. exec "${HADOOP_HDFS_HOME}"/bin/hdfs $*
  50. elif [ -f "${HADOOP_HOME}"/bin/hdfs ]; then
  51. exec "${HADOOP_HOME}"/bin/hdfs $*
  52. else
  53. echo "HDFS not found."
  54. exit
  55. fi
  56. ;;
  57. #mapred commands
  58. mradmin|jobtracker|tasktracker|pipes|job|queue)
  59. echo "DEPRECATED: Use of this script to execute mapred command is deprecated."
  60. echo "Instead use the mapred command for it."
  61. echo ""
  62. #try to locate mapred and if present, delegate to it.
  63. if [ -f "${HADOOP_MAPRED_HOME}"/bin/mapred ]; then
  64. exec "${HADOOP_MAPRED_HOME}"/bin/mapred $*
  65. elif [ -f "${HADOOP_HOME}"/bin/mapred ]; then
  66. exec "${HADOOP_HOME}"/bin/mapred $*
  67. else
  68. echo "MAPRED not found."
  69. exit
  70. fi
  71. ;;
  72. classpath)
  73. if $cygwin; then
  74. CLASSPATH=`cygpath -p -w "$CLASSPATH"`
  75. fi
  76. echo $CLASSPATH
  77. exit
  78. ;;
  79. #core commands
  80. *)
  81. # the core commands
  82. if [ "$COMMAND" = "fs" ] ; then
  83. CLASS=org.apache.hadoop.fs.FsShell
  84. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  85. elif [ "$COMMAND" = "version" ] ; then
  86. CLASS=org.apache.hadoop.util.VersionInfo
  87. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  88. elif [ "$COMMAND" = "jar" ] ; then
  89. CLASS=org.apache.hadoop.util.RunJar
  90. elif [ "$COMMAND" = "distcp" ] ; then
  91. CLASS=org.apache.hadoop.tools.DistCp
  92. CLASSPATH=${CLASSPATH}:${TOOL_PATH}
  93. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  94. elif [ "$COMMAND" = "daemonlog" ] ; then
  95. CLASS=org.apache.hadoop.log.LogLevel
  96. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  97. elif [ "$COMMAND" = "archive" ] ; then
  98. CLASS=org.apache.hadoop.tools.HadoopArchives
  99. CLASSPATH=${CLASSPATH}:${TOOL_PATH}
  100. HADOOP_OPTS="$HADOOP_OPTS $HADOOP_CLIENT_OPTS"
  101. else
  102. CLASS=$COMMAND
  103. fi
  104. shift
  105. if $cygwin; then
  106. CLASSPATH=`cygpath -p -w "$CLASSPATH"`
  107. fi
  108. export CLASSPATH=$CLASSPATH
  109. exec "$JAVA" $JAVA_HEAP_MAX $HADOOP_OPTS $CLASS "$@"
  110. ;;
  111. esac