123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- #!/usr/bin/env bash
- # Licensed to the Apache Software Foundation (ASF) under one or more
- # contributor license agreements. See the NOTICE file distributed with
- # this work for additional information regarding copyright ownership.
- # The ASF licenses this file to You 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
- #JAVA_HOME=/usr/jdk64/jdk1.7.0_45
- PIDFILE=/var/run/ambari-metrics-collector/ambari-metrics-collector.pid
- OUTFILE=/var/log/ambari-metrics-collector/ambari-metrics-collector.out
- HBASE_ZK_PID=/var/run/ams-hbase/hbase-hbase-zookeeper.pid
- HBASE_MASTER_PID=/var/run/ams-hbase/hbase-hbase-master.pid
- HBASE_RS_PID=/var/run/ams-hbase/hbase-hbase-regionserver.pid
- HBASE_DIR=/usr/lib/ams-hbase
- DAEMON_NAME=timelineserver
- COLLECTOR_CONF_DIR=/etc/ambari-metrics-collector/conf
- HBASE_CONF_DIR=/etc/ams-hbase/conf
- METRIC_COLLECTOR=ambari-metrics-collector
- AMS_LOG_DIR=/var/log/ambari-metrics-collector
- STOP_TIMEOUT=5
- function hbase_daemon
- {
- local daemon=$1
- local cmd=$2
- local pid
- case "${daemon}" in
- "master")
- pid=${HBASE_MASTER_PID}
- ;;
- "zookeeper")
- pid=${HBASE_ZK_PID}
- ;;
- "regionserver")
- pid=${HBASE_RS_PID}
- ;;
- esac
- daemon_status "${pid}"
- if [[ $? == 0 ]]; then
- echo "${daemon} is running as process $(cat "${pid}"). Continuing"
- else
- # stale pid file, so just remove it and continue on
- rm -f "${pid}" >/dev/null 2>&1
- fi
- ${HBASE_DIR}/bin/hbase-daemon.sh --config ${HBASE_CONF_DIR} ${cmd} ${daemon}
- }
- function write_pidfile
- {
- local pidfile="$1"
- echo $! > "${pidfile}" 2>/dev/null
- if [[ $? -gt 0 ]]; then
- echo "ERROR: Cannot write pid ${pidfile}."
- exit 1;
- fi
- }
- function hadoop_java_setup
- {
- # Bail if we did not detect it
- if [[ -z "${JAVA_HOME}" ]]; then
- echo "ERROR: JAVA_HOME is not set and could not be found."
- exit 1
- fi
- if [[ ! -d "${JAVA_HOME}" ]]; then
- echo "ERROR: JAVA_HOME ${JAVA_HOME} does not exist."
- exit 1
- fi
- JAVA="${JAVA_HOME}/bin/java"
- if [[ ! -x "$JAVA" ]]; then
- echo "ERROR: $JAVA is not executable."
- exit 1
- fi
- # shellcheck disable=SC2034
- JAVA_HEAP_MAX=-Xmx1g
- HADOOP_HEAPSIZE=${HADOOP_HEAPSIZE:-1024}
- # check envvars which might override default args
- if [[ -n "$HADOOP_HEAPSIZE" ]]; then
- # shellcheck disable=SC2034
- JAVA_HEAP_MAX="-Xmx${HADOOP_HEAPSIZE}m"
- fi
- }
- function daemon_status()
- {
- #
- # LSB 4.1.0 compatible status command (1)
- #
- # 0 = program is running
- # 1 = dead, but still a pid (2)
- # 2 = (not used by us)
- # 3 = not running
- #
- # 1 - this is not an endorsement of the LSB
- #
- # 2 - technically, the specification says /var/run/pid, so
- # we should never return this value, but we're giving
- # them the benefit of a doubt and returning 1 even if
- # our pid is not in in /var/run .
- #
- local pidfile="$1"
- shift
- local pid
- if [[ -f "${pidfile}" ]]; then
- pid=$(cat "${pidfile}")
- if ps -p "${pid}" > /dev/null 2>&1; then
- return 0
- fi
- return 1
- fi
- return 3
- }
- while [[ -z "${_ams_configs_done}" ]]; do
- case $1 in
- --config)
- shift
- confdir=$1
- shift
- if [[ -d "${confdir}" ]]; then
- COLLECTOR_CONF_DIR="${confdir}"
- elif [[ -z "${confdir}" ]]; then
- echo "ERROR: No parameter provided for --config "
- exit 1
- else
- echo "ERROR: Cannot find configuration directory \"${confdir}\""
- exit 1
- fi
- ;;
- *)
- _ams_configs_done=true
- ;;
- esac
- done
- # execute ams-env.sh
- if [[ -f "${COLLECTOR_CONF_DIR}/ams-env.sh" ]]; then
- . "${COLLECTOR_CONF_DIR}/ams-env.sh"
- else
- echo "ERROR: Cannot execute ${COLLECTOR_CONF_DIR}/ams-env.sh." 2>&1
- exit 1
- fi
- # set pid dir path
- if [[ -n "${AMS_PID_DIR}" ]]; then
- PIDFILE=${AMS_PID_DIR}/ambari-metrics-collector.pid
- fi
- # set out file path
- if [[ -n "${AMS_COLLECTOR_LOG_DIR}" ]]; then
- OUTFILE=${AMS_COLLECTOR_LOG_DIR}/ambari-metrics-collector.out
- fi
- #TODO manage 3 hbase daemons for start/stop/status
- case "$1" in
- start)
- hadoop_java_setup
- #hbase_daemon "zookeeper" "start"
- hbase_daemon "master" "start"
- #hbase_daemon "regionserver" "start"
- sleep 30
- CLASS='org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryServer'
- # YARN_OPTS="${YARN_OPTS} ${YARN_TIMELINESERVER_OPTS}"
- # if [[ -n "${YARN_TIMELINESERVER_HEAPSIZE}" ]]; then
- # JAVA_HEAP_MAX="-Xmx${YARN_TIMELINESERVER_HEAPSIZE}m"
- # fi
-
- # check if this is needed?
- # export PHOENIX_JAR_PATH=/usr/lib/ambari-metrics/timelineservice/phoenix-client.jar
- # export HBASE_CONF_DIR=${HBASE_DIR}/conf
- daemon_status "${PIDFILE}"
- if [[ $? == 0 ]]; then
- echo "AMS is running as process $(cat "${PIDFILE}"). Exiting"
- exit 1
- else
- # stale pid file, so just remove it and continue on
- rm -f "${PIDFILE}" >/dev/null 2>&1
- fi
- nohup "${JAVA}" "-cp" "/usr/lib/ambari-metrics-collector/*:${COLLECTOR_CONF_DIR}" "-Djava.net.preferIPv4Stack=true" "-Dams.log.dir=${AMS_COLLECTOR_LOG_DIR}" "-Dproc_${DAEMON_NAME}" "${CLASS}" "$@" > $OUTFILE 2>&1 &
- PID=$!
- write_pidfile "${PIDFILE}"
- sleep 2
- echo "Verifying ${METRIC_COLLECTOR} process status..."
- if [ -z "`ps ax -o pid | grep ${PID}`" ]; then
- if [ -s ${OUTFILE} ]; then
- echo "ERROR: ${METRIC_COLLECTOR} start failed. For more details, see ${OUTFILE}:"
- echo "===================="
- tail -n 10 ${OUTFILE}
- echo "===================="
- else
- echo "ERROR: ${METRIC_COLLECTOR} start failed"
- rm -f ${PIDFILE}
- fi
- echo "Collector out at: ${OUTFILE}"
- exit -1
- fi
- echo "Collector successfully started."
- ;;
- stop)
- pidfile=${PIDFILE}
- if [[ -f "${pidfile}" ]]; then
- pid=$(cat "$pidfile")
- kill "${pid}" >/dev/null 2>&1
- sleep "${STOP_TIMEOUT}"
- if kill -0 "${pid}" > /dev/null 2>&1; then
- echo "WARNING: ${METRIC_COLLECTOR} did not stop gracefully after ${STOP_TIMEOUT} seconds: Trying to kill with kill -9"
- kill -9 "${pid}" >/dev/null 2>&1
- fi
- if ps -p "${pid}" > /dev/null 2>&1; then
- echo "ERROR: Unable to kill ${pid}"
- else
- rm -f "${pidfile}" >/dev/null 2>&1
- fi
- fi
- #stop hbase daemons
- #hbase_daemon "zookeeper" "stop"
- hbase_daemon "master" "stop"
- #hbase_daemon "regionserver" "stop"
- ;;
- status)
- daemon_status "${PIDFILE}"
- if [[ $? == 0 ]]; then
- echo "AMS is running as process $(cat "${PIDFILE}")."
- else
- echo "AMS is not running."
- fi
- #print embedded hbase daemons statuses?
- ;;
- restart)
- ;;
- esac
|