hadoop-tasktracker 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #! /bin/sh
  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. ### BEGIN INIT INFO
  17. # Provides: hadoop-tasktracker
  18. # Required-Start: $remote_fs $syslog
  19. # Required-Stop: $remote_fs $syslog
  20. # Default-Start: 2 3 4 5
  21. # Default-Stop:
  22. # Short-Description: Apache Hadoop Task Tracker server
  23. ### END INIT INFO
  24. set -e
  25. # /etc/init.d/hadoop-tasktracker: start and stop the Apache Hadoop Task Tracker daemon
  26. test -x /usr/bin/hadoop || exit 0
  27. ( /usr/bin/hadoop 2>&1 | grep -q hadoop ) 2>/dev/null || exit 0
  28. umask 022
  29. if test -f /etc/default/hadoop-env.sh; then
  30. . /etc/default/hadoop-env.sh
  31. fi
  32. . /lib/lsb/init-functions
  33. # Are we running from init?
  34. run_by_init() {
  35. ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ]
  36. }
  37. check_for_no_start() {
  38. # forget it if we're trying to start, and /etc/hadoop/hadoop-tasktracker_not_to_be_run exists
  39. if [ -e /etc/hadoop/hadoop-tasktracker_not_to_be_run ]; then
  40. if [ "$1" = log_end_msg ]; then
  41. log_end_msg 0
  42. fi
  43. if ! run_by_init; then
  44. log_action_msg "Apache Hadoop Task Tracker server not in use (/etc/hadoop/hadoop-tasktracker_not_to_be_run)"
  45. fi
  46. exit 0
  47. fi
  48. }
  49. check_privsep_dir() {
  50. # Create the PrivSep empty dir if necessary
  51. if [ ! -d ${HADOOP_PID_DIR} ]; then
  52. mkdir -p ${HADOOP_PID_DIR}
  53. chown root:hadoop ${HADOOP_PID_DIR}
  54. chmod 0775 ${HADOOP_PID_DIR}
  55. fi
  56. }
  57. export PATH="${PATH:+$PATH:}/usr/sbin:/usr/bin"
  58. export HADOOP_PREFIX=${HADOOP_PREFIX:-/usr}
  59. case "$1" in
  60. start)
  61. check_privsep_dir
  62. check_for_no_start
  63. log_daemon_msg "Starting Apache Hadoop Task Tracker server" "hadoop-tasktracker"
  64. if start-stop-daemon --start --quiet --oknodo --pidfile ${HADOOP_PID_DIR}/hadoop-mapred-tasktracker.pid -c mapred -x ${HADOOP_PREFIX}/sbin/hadoop-daemon.sh -- --config ${HADOOP_CONF_DIR} start tasktracker; then
  65. log_end_msg 0
  66. else
  67. log_end_msg 1
  68. fi
  69. ;;
  70. stop)
  71. log_daemon_msg "Stopping Apache Hadoop Task Tracker server" "hadoop-tasktracker"
  72. if start-stop-daemon --stop --quiet --oknodo --pidfile ${HADOOP_PID_DIR}/hadoop-mapred-tasktracker.pid; then
  73. log_end_msg 0
  74. else
  75. log_end_msg 1
  76. fi
  77. ;;
  78. restart)
  79. check_privsep_dir
  80. log_daemon_msg "Restarting Apache Hadoop Task Tracker server" "hadoop-tasktracker"
  81. start-stop-daemon --stop --quiet --oknodo --retry 30 --pidfile ${HADOOP_PID_DIR}/hadoop-mapred-tasktracker.pid
  82. check_for_no_start log_end_msg
  83. if start-stop-daemon --start --quiet --oknodo --pidfile ${HADOOP_PID_DIR}/hadoop-mapred-tasktracker.pid -c mapred -x ${HADOOP_PREFIX}/sbin/hadoop-daemon.sh -- --config ${HADOOP_CONF_DIR} start tasktracker; then
  84. log_end_msg 0
  85. else
  86. log_end_msg 1
  87. fi
  88. ;;
  89. try-restart)
  90. check_privsep_dir
  91. log_daemon_msg "Restarting Apache Hadoop Task Tracker server" "hadoop-tasktracker"
  92. set +e
  93. start-stop-daemon --stop --quiet --retry 30 --pidfile ${HADOOP_PID_DIR}/hadoop-mapred-tasktracker.pid
  94. RET="$?"
  95. set -e
  96. case $RET in
  97. 0)
  98. # old daemon stopped
  99. check_for_no_start log_end_msg
  100. if start-stop-daemon --start --quiet --oknodo --pidfile ${HADOOP_PID_DIR}/hadoop-mapred-tasktracker.pid -c mapred -x ${HADOOP_PREFIX}/sbin/hadoop-daemon.sh -- --config ${HADOOP_CONF_DIR} start tasktracker; then
  101. log_end_msg 0
  102. else
  103. log_end_msg 1
  104. fi
  105. ;;
  106. 1)
  107. # daemon not running
  108. log_progress_msg "(not running)"
  109. log_end_msg 0
  110. ;;
  111. *)
  112. # failed to stop
  113. log_progress_msg "(failed to stop)"
  114. log_end_msg 1
  115. ;;
  116. esac
  117. ;;
  118. status)
  119. status_of_proc -p ${HADOOP_PID_DIR}/hadoop-mapred-tasktracker.pid ${JAVA_HOME}/bin/java hadoop-tasktracker && exit 0 || exit $?
  120. ;;
  121. *)
  122. log_action_msg "Usage: /etc/init.d/hadoop-tasktracker {start|stop|restart|try-restart|status}"
  123. exit 1
  124. esac
  125. exit 0