#! /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.
# Guarantees that Accumulo and its environment variables are set.
#
# Values set by script that can be user provided. If not provided script attempts to infer.
# ACCUMULO_CONF_DIR Location where accumulo-env.sh, accumulo-site.xml and friends will be read from
# ACCUMULO_LOG_DIR Directory for Accumulo daemon logs
# JAVA_HOME Directory Java
#
# Values always set by script.
# MALLOC_ARENA_MAX To work around a memory management bug (see ACCUMULO-847)
#
# Values set by script if certain files exist
# ACCUMULO_JAAS_CONF Location of jaas.conf file. Needed by JAAS for things like Kerberos based logins
# ACCUMULO_KRB5_CONF Location of krb5.conf file. Needed by Kerberos subsystems to find login servers
# Set the configuration directory
export ACCUMULO_CONF_DIR=${ACCUMULO_CONF_DIR:-/etc/accumulo}
if [[ -z $ACCUMULO_CONF_DIR || ! -d $ACCUMULO_CONF_DIR || ! -r $ACCUMULO_CONF_DIR || ! -x $ACCUMULO_CONF_DIR ]]; then
echo "ACCUMULO_CONF_DIR=$ACCUMULO_CONF_DIR is not a valid directory. Please make sure it exists and can be read." 1>&2
exit 1
fi
export ACCUMULO_HOME="${ACCUMULO_HOME:-$ACCUMULO_CONF_DIR}"
# Read environment configuration
if [[ -f "$ACCUMULO_CONF_DIR/accumulo-env.sh" ]]; then
. "$ACCUMULO_CONF_DIR/accumulo-env.sh"
fi
# Set the log directory
export ACCUMULO_LOG_DIR=${ACCUMULO_LOG_DIR:-/var/log/accumulo}
if [[ -z $ACCUMULO_LOG_DIR || ! -d $ACCUMULO_LOG_DIR || ! -w $ACCUMULO_LOG_DIR || ! -x $ACCUMULO_LOG_DIR ]]; then
echo "ACCUMULO_LOG_DIR=$ACCUMULO_LOG_DIR is not a valid directory. Please make sure it exists and can be written. Or, override this in $ACCUMULO_CONF_DIR/accumulo-env.sh" 1>&2
exit 1
fi
# See HADOOP-7154 and ACCUMULO-847
export MALLOC_ARENA_MAX=${MALLOC_ARENA_MAX:-1}
# ACCUMULO-1985 provide a way to use the scripts and still bind to all network interfaces
export ACCUMULO_MONITOR_BIND_ALL=${ACCUMULO_MONITOR_BIND_ALL:-"false"}
# Check for jaas.conf configuration
if [[ -z $ACCUMULO_JAAS_CONF && -f "$ACCUMULO_CONF_DIR/jaas.conf" ]]; then
export ACCUMULO_JAAS_CONF=${ACCUMULO_CONF_DIR}/jaas.conf
fi
if [[ -n $ACCUMULO_JAAS_CONF ]]; then
export ACCUMULO_GENERAL_OPTS="${ACCUMULO_GENERAL_OPTS} -Djava.security.auth.login.config=${ACCUMULO_JAAS_CONF}"
fi
# Check for krb5.conf configuration
if [[ -z $ACCUMULO_KRB5_CONF && -f "${ACCUMULO_CONF_DIR}/krb5.conf" ]]; then
export ACCUMULO_KRB5_CONF=${ACCUMULO_CONF_DIR}/krb5.conf
fi
if [[ -n $ACCUMULO_KRB5_CONF ]]; then
export ACCUMULO_GENERAL_OPTS="${ACCUMULO_GENERAL_OPTS} -Djava.security.krb5.conf=${ACCUMULO_KRB5_CONF}"
fi
#
# Add appropriate options for process type
#
case "$1" in
master) export ACCUMULO_OPTS="${ACCUMULO_GENERAL_OPTS} ${ACCUMULO_MASTER_OPTS}" ;;
gc) export ACCUMULO_OPTS="${ACCUMULO_GENERAL_OPTS} ${ACCUMULO_GC_OPTS}" ;;
tserver) export ACCUMULO_OPTS="${ACCUMULO_GENERAL_OPTS} ${ACCUMULO_TSERVER_OPTS}" ;;
monitor) export ACCUMULO_OPTS="${ACCUMULO_GENERAL_OPTS} ${ACCUMULO_MONITOR_OPTS}" ;;
logger) export ACCUMULO_OPTS="${ACCUMULO_GENERAL_OPTS} ${ACCUMULO_LOGGER_OPTS}" ;;
*) export ACCUMULO_OPTS="${ACCUMULO_GENERAL_OPTS} ${ACCUMULO_OTHER_OPTS}" ;;
esac
function getClasspath() {
/usr/bin/build-classpath \
accumulo \
accumulo/accumulo-tserver \
apache-commons-cli \
apache-commons-codec \
apache-commons-collections \
apache-commons-configuration \
apache-commons-lang \
apache-commons-logging \
apache-commons-math \
apache-commons-vfs \
beust-jcommander \
guava \
hadoop/hadoop-auth \
hadoop/hadoop-common \
hadoop/hadoop-hdfs \
jansi/jansi \
jline/jline \
libthrift \
log4j-1.2.17 \
slf4j/slf4j-api \
slf4j/slf4j-log4j12 \
zookeeper/zookeeper \
;
}
export CLASSPATH="${ACCUMULO_CONF_DIR}:$(getClasspath)"
export JAVA_HOME=${JAVA_HOME:-$(dirname $(dirname $(readlink -ef $(which java))))}
export JAVA="${JAVA_HOME}/bin/java"
# app isn't used anywhere, but it makes the process easier to spot when ps/top/snmp truncate the command line
# swap stderr and stdout to pipe stderr to logger, then move logger's echo to
# stdout, before swapping back, so the caller sees what they'd expect
($JAVA "-Dapp=$1" \
$ACCUMULO_OPTS \
-classpath "${CLASSPATH}" \
-XX:OnOutOfMemoryError="${ACCUMULO_KILL_CMD:-kill -9 %p}" \
-XX:-OmitStackTraceInFastThrow \
-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl \
org.apache.accumulo.start.Main \
"$@" 3>&1 1>&2 2>&3 | logger -i -s 2>&1) 3>&1 1>&2 2>&3