#!/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 language governing permissions and # limitations under the License. # The Ambari command script # # Environment Variables # # JAVA_HOME The java implementation to use. Overrides JAVA_HOME. # AMBARI_CONF_DIR Alternate conf dir. Default is ${AMBARI_HOME}/conf. # bin=`dirname "$0"` bin=`cd "$bin"; pwd` . "$bin"/ambari-config.sh # if no args specified, show usage if [ $# = 0 ]; then echo "Usage: $0 [--config confdir] COMMAND" echo "where COMMAND is one of:" echo " controller run Ambari Controller" echo " client run Ambari client" echo " version print the version" exit 1 fi # get arguments COMMAND=$1 shift if [ -f "${AMBARI_CONF_DIR}/ambari-env.sh" ]; then . "${AMBARI_CONF_DIR}/ambari-env.sh" fi # Java parameters if [ "$JAVA_HOME" != "" ]; then JAVA_HOME=$JAVA_HOME fi if [ "$JAVA_HOME" = "" ]; then echo "Error: JAVA_HOME is not set." exit 1 fi if [ "$AMBARI_CONF_DIR" != "" ]; then CLASSPATH=${AMBARI_CONF_DIR}:${CLASSPATH} fi BACKGROUND="false" # configure command parameters if [ "$COMMAND" = "agent" ]; then APP='agent' PID="ambari-agent" elif [ "$COMMAND" = "beacon" ]; then APP='beacon' CLASS='org.apache.ambari.beacon.Beacon' PID="ambari-$AMBARI_IDENT_STRING-beacon" BACKGROUND="true" elif [ "$COMMAND" = "controller" ]; then APP='controller' CLASS='org.apache.ambari.controller.Controller' PID="ambari-$AMBARI_IDENT_STRING-controller" BACKGROUND="true" elif [ "$COMMAND" = "client" ]; then APP='client' CLASS='org.apache.ambari.client.AmbariClient' PID="client" elif [ "$COMMAND" = "version" ]; then echo `cat ${AMBARI_HOME}/bin/VERSION` exit 0 fi if [ "$1" = "stop" ]; then if [ -e ${AMBARI_PID_DIR}/${PID}.pid ]; then kill -TERM `cat ${AMBARI_PID_DIR}/$PID.pid` else echo "${PID} is not running." fi else if [ "$APP" = "agent" ]; then echo else # run command RUN="${JAVA_HOME}/bin/java ${JAVA_OPT} -Djava.library.path=${JAVA_LIBRARY_PATH} -DPID=${PID} -DAMBARI_HOME=${AMBARI_HOME} -DAMBARI_CONF_DIR=${AMBARI_CONF_DIR} -DAMBARI_LOG_DIR=${AMBARI_LOG_DIR} -DAMBARI_DATA_DIR=${AMBARI_DATA_DIR} -DAPP=${APP} -Dlog4j.configuration=log4j.properties -classpath ${AMBARI_CONF_DIR}:${CLASSPATH}:${AMBARI_CONTROLLER}:${AMBARI_JAR}:${COMMON}:${tools} ${CLASS} $OPTS $@" if [ "$BACKGROUND" = "true" ]; then exec ${RUN} & else exec ${RUN} fi fi fi