From 5991c218a0cd72fc6a2b10ef77729ee6181c9443 Mon Sep 17 00:00:00 2001 From: Subru Krishnan Date: Thu, 9 Nov 2017 00:32:34 -0800 Subject: [PATCH] HADOOP-15026. Rebase ResourceEstimator start/stop scripts for branch-2. (Rui Li via Subru). --- .../src/main/bin/estimator-daemon.sh | 79 +++++++++++++++++++ .../src/main/bin/estimator.sh | 52 ++++-------- .../src/main/bin/start-estimator.sh | 30 +------ .../src/main/bin/stop-estimator.sh | 29 +------ 4 files changed, 104 insertions(+), 86 deletions(-) create mode 100755 hadoop-tools/hadoop-resourceestimator/src/main/bin/estimator-daemon.sh diff --git a/hadoop-tools/hadoop-resourceestimator/src/main/bin/estimator-daemon.sh b/hadoop-tools/hadoop-resourceestimator/src/main/bin/estimator-daemon.sh new file mode 100755 index 00000000000..34a98c0fdca --- /dev/null +++ b/hadoop-tools/hadoop-resourceestimator/src/main/bin/estimator-daemon.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. See accompanying LICENSE file. +# + +bin=$(dirname "${BASH_SOURCE-$0}") +bin=$(cd "$bin" || exit; pwd) + +# get arguments +startStop=$1 +shift +command=$1 +shift + +pid=/tmp/hadoop-dogtail-estimator.pid + +LOG_DIR=$bin/../../../../../logs +if [ ! -w "$LOG_DIR" ] ; then + mkdir -p "$LOG_DIR" +fi + +log=$LOG_DIR/hadoop-resourceestimator.out + +case $startStop in + + (start) + + if [ -f $pid ]; then + # shellcheck disable=SC2046 + if kill -0 $(cat $pid) > /dev/null 2>&1; then + echo "$command running as process $(cat $pid). Stop it first." + exit 1 + fi + fi + + echo "starting $command, logging to $log" + bin/estimator.sh "$@" > "$log" 2>&1 < /dev/null & + echo $! > $pid + sleep 1 + head "$log" + ;; + + (stop) + + if [ -f $pid ]; then + TARGET_PID=$(cat $pid) + # shellcheck disable=SC2086 + if kill -0 $TARGET_PID > /dev/null 2>&1; then + kill "$TARGET_PID" + sleep 5 + # shellcheck disable=SC2086 + if kill -0 $TARGET_PID > /dev/null 2>&1; then + echo "$command did not stop gracefully after 5 seconds: killing with kill -9" + "kill -9 $TARGET_PID" + fi + else + echo "no $command to stop" + fi + rm -f $pid + else + echo "no $command to stop" + fi + ;; + + (*) + exit 1 + ;; + +esac \ No newline at end of file diff --git a/hadoop-tools/hadoop-resourceestimator/src/main/bin/estimator.sh b/hadoop-tools/hadoop-resourceestimator/src/main/bin/estimator.sh index 3e1ec278a9d..e48238c643f 100644 --- a/hadoop-tools/hadoop-resourceestimator/src/main/bin/estimator.sh +++ b/hadoop-tools/hadoop-resourceestimator/src/main/bin/estimator.sh @@ -13,32 +13,21 @@ # limitations under the License. See accompanying LICENSE file. # -## @audience public -## @stability stable -function hadoop_usage() -{ - echo "Usage: estimator.sh" - #hadoop-daemon.sh. need both start and stop, status (query the status). run as background process. -} +bin=$(dirname "${BASH_SOURCE-$0}") +bin=$(cd "$bin" || exit; pwd) -## @audience public -## @stability stable -function calculate_classpath -{ - hadoop_add_client_opts - hadoop_add_to_classpath_tools hadoop-resourceestimator -} +# some Java parameters +if [ "$JAVA_HOME" != "" ]; then + #echo "run java in $JAVA_HOME" + JAVA_HOME=$JAVA_HOME +fi -## @audience public -## @stability stable -function resourceestimatorcmd_case -{ - # shellcheck disable=SC2034 - HADOOP_SUBCMD_SUPPORTDAEMONIZATION="true" - # shellcheck disable=SC2034 - HADOOP_CLASSNAME='org.apache.hadoop.resourceestimator.service.ResourceEstimatorServer' -} +if [ "$JAVA_HOME" = "" ]; then + echo "Error: JAVA_HOME is not set." + exit 1 +fi +JAVA=$JAVA_HOME/bin/java # let's locate libexec... if [[ -n "${HADOOP_HOME}" ]]; then HADOOP_DEFAULT_LIBEXEC_DIR="${HADOOP_HOME}/libexec" @@ -49,8 +38,6 @@ else fi HADOOP_LIBEXEC_DIR="${HADOOP_LIBEXEC_DIR:-$HADOOP_DEFAULT_LIBEXEC_DIR}" -# shellcheck disable=SC2034 -HADOOP_NEW_CONFIG=true if [[ -f "${HADOOP_LIBEXEC_DIR}/hadoop-config.sh" ]]; then # shellcheck source=./hadoop-common-project/hadoop-common/src/main/bin/hadoop-config.sh . "${HADOOP_LIBEXEC_DIR}/hadoop-config.sh" @@ -58,14 +45,9 @@ else echo "ERROR: Cannot execute ${HADOOP_LIBEXEC_DIR}/hadoop-config.sh." 2>&1 exit 1 fi +# shellcheck disable=SC2125 +CLASSPATH=${CLASSPATH}:$bin/../../lib/* -# get arguments -HADOOP_SUBCMD=$1 -shift - -HADOOP_SUBCMD_ARGS=("$@") - -resourceestimatorcmd_case "${HADOOP_SUBCMD}" "${HADOOP_SUBCMD_ARGS[@]}" - -calculate_classpath -hadoop_generic_java_subcmd_handler +CLASS=org.apache.hadoop.resourceestimator.service.ResourceEstimatorServer +# shellcheck disable=SC2086 +exec "$JAVA" -Dproc_$COMMAND -classpath "$CLASSPATH" $CLASS "$@" diff --git a/hadoop-tools/hadoop-resourceestimator/src/main/bin/start-estimator.sh b/hadoop-tools/hadoop-resourceestimator/src/main/bin/start-estimator.sh index bf4328adae2..59cb6741bfb 100644 --- a/hadoop-tools/hadoop-resourceestimator/src/main/bin/start-estimator.sh +++ b/hadoop-tools/hadoop-resourceestimator/src/main/bin/start-estimator.sh @@ -13,30 +13,8 @@ # limitations under the License. See accompanying LICENSE file. # -# let's locate libexec... -if [[ -n "${HADOOP_HOME}" ]]; then - HADOOP_DEFAULT_LIBEXEC_DIR="${HADOOP_HOME}/libexec" -else - this="${BASH_SOURCE-$0}" - bin=$(cd -P -- "$(dirname -- "${this}")" >/dev/null && pwd -P) - HADOOP_DEFAULT_LIBEXEC_DIR="${bin}/../../../../../libexec" -fi +echo "starting resource estimator service" -HADOOP_LIBEXEC_DIR="${HADOOP_LIBEXEC_DIR:-$HADOOP_DEFAULT_LIBEXEC_DIR}" -# shellcheck disable=SC2034 -HADOOP_NEW_CONFIG=true -if [[ -f "${HADOOP_LIBEXEC_DIR}/hadoop-config.sh" ]]; then - # shellcheck source=./hadoop-common-project/hadoop-common/src/main/bin/hadoop-config.sh - . "${HADOOP_LIBEXEC_DIR}/hadoop-config.sh" -else - echo "ERROR: Cannot execute ${HADOOP_LIBEXEC_DIR}/hadoop-config.sh." 2>&1 - exit 1 -fi - -# start resource estimator -echo "Starting resource estimator" -hadoop_uservar_su estimator resourceestimator "bin/estimator.sh" \ - --config "${HADOOP_CONF_DIR}" \ - --daemon start \ - resourceestimator -(( HADOOP_JUMBO_RETCOUNTER=HADOOP_JUMBO_RETCOUNTER + $? )) +bin=$(dirname "${BASH_SOURCE-$0}") +bin=$(cd "$bin" || exit; pwd) +"$bin"/estimator-daemon.sh start estimator diff --git a/hadoop-tools/hadoop-resourceestimator/src/main/bin/stop-estimator.sh b/hadoop-tools/hadoop-resourceestimator/src/main/bin/stop-estimator.sh index e78c7983332..7552c9ec9b7 100644 --- a/hadoop-tools/hadoop-resourceestimator/src/main/bin/stop-estimator.sh +++ b/hadoop-tools/hadoop-resourceestimator/src/main/bin/stop-estimator.sh @@ -13,30 +13,9 @@ # limitations under the License. See accompanying LICENSE file. # -# let's locate libexec... -if [[ -n "${HADOOP_HOME}" ]]; then - HADOOP_DEFAULT_LIBEXEC_DIR="${HADOOP_HOME}/libexec" -else - this="${BASH_SOURCE-$0}" - bin=$(cd -P -- "$(dirname -- "${this}")" >/dev/null && pwd -P) - HADOOP_DEFAULT_LIBEXEC_DIR="${bin}/../../../../../libexec" -fi +echo "stopping resource estimator service" -HADOOP_LIBEXEC_DIR="${HADOOP_LIBEXEC_DIR:-$HADOOP_DEFAULT_LIBEXEC_DIR}" -# shellcheck disable=SC2034 -HADOOP_NEW_CONFIG=true -if [[ -f "${HADOOP_LIBEXEC_DIR}/hadoop-config.sh" ]]; then - # shellcheck source=./hadoop-common-project/hadoop-common/src/main/bin/hadoop-config.sh - . "${HADOOP_LIBEXEC_DIR}/hadoop-config.sh" -else - echo "ERROR: Cannot execute ${HADOOP_LIBEXEC_DIR}/hadoop-config.sh." 2>&1 - exit 1 -fi +bin=$(dirname "${BASH_SOURCE-$0}") +bin=$(cd "$bin" || exit; pwd) -# stop resource estimator -echo "Stopping resource estimator" -hadoop_uservar_su estimator resourceestimator "bin/estimator.sh" \ - --config "${HADOOP_CONF_DIR}" \ - --daemon stop \ - resourceestimator -(( HADOOP_JUMBO_RETCOUNTER=HADOOP_JUMBO_RETCOUNTER + $? )) +"$bin"/estimator-daemon.sh stop estimator