Blob Blame History Raw
#! /usr/bin/env bash

# Set important directory locations, if not already set
# Configure the configuration directory; this is needed on the classpath
ACCUMULO_CONF_DIR=${ACCUMULO_CONF_DIR:-/etc/accumulo}
# Configure the log directory; this is referenced by logger configuration
ACCUMULO_LOG_DIR=${ACCUMULO_LOG_DIR:-/var/log/accumulo}

# Java security policy, if present
[[ -f "${ACCUMULO_CONF_DIR}/accumulo.policy" ]] && POLICY=('-Djava.security.manager' "-Djava.security.policy='${ACCUMULO_CONF_DIR}/accumulo.policy'") || POLICY=()

# Configure authentication/kerberos security options
ACCUMULO_SECURITY_OPTS=()

# Check for jaas.conf configuration
[[ -z $ACCUMULO_JAAS_CONF && -f "$ACCUMULO_CONF_DIR/jaas.conf" ]] && ACCUMULO_JAAS_CONF="${ACCUMULO_CONF_DIR}/jaas.conf"
[[ -n $ACCUMULO_JAAS_CONF ]] && ACCUMULO_SECURITY_OPTS=("-Djava.security.auth.login.config='${ACCUMULO_JAAS_CONF}'")

# Check for krb5.conf configuration
[[ -z $ACCUMULO_KRB5_CONF && -f "${ACCUMULO_CONF_DIR}/krb5.conf" ]] && ACCUMULO_KRB5_CONF="${ACCUMULO_CONF_DIR}/krb5.conf"
[[ -n $ACCUMULO_KRB5_CONF ]] && ACCUMULO_SECURITY_OPTS=("-Djava.security.krb5.conf='${ACCUMULO_KRB5_CONF}'")

# Set options for individual services, if not already set
[[ -n $ACCUMULO_TSERVER_OPTS ]] || ACCUMULO_TSERVER_OPTS=("${POLICY[@]}" '-Xmx1g' '-Xms1g' '-XX:NewSize=500m' '-XX:MaxNewSize=500m')
[[ -n $ACCUMULO_MASTER_OPTS  ]] || ACCUMULO_MASTER_OPTS=("${POLICY[@]}" '-Xmx1g' '-Xms1g')
[[ -n $ACCUMULO_MONITOR_OPTS ]] || ACCUMULO_MONITOR_OPTS=("${POLICY[@]}" '-Xmx1g' '-Xms256m')
[[ -n $ACCUMULO_GC_OPTS      ]] || ACCUMULO_GC_OPTS=("${POLICY[@]}" '-Xmx256m' '-Xms256m')
[[ -n $ACCUMULO_OTHER_OPTS   ]] || ACCUMULO_OTHER_OPTS=('-Xmx1g' '-Xms256m')

# Set what do when the JVM runs out of heap memory, if not already set
ACCUMULO_KILL_CMD=${ACCUMULO_KILL_CMD:-kill -9 %p}

# See HADOOP-7154 and ACCUMULO-847
MALLOC_ARENA_MAX=${MALLOC_ARENA_MAX:-1}

# Configure general options
[[ -n $ACCUMULO_GENERAL_OPTS ]] || ACCUMULO_GENERAL_OPTS=('-XX:+UseConcMarkSweepGC' '-XX:CMSInitiatingOccupancyFraction=75' '-Djava.net.preferIPv4Stack=true' '-XX:-OmitStackTraceInFastThrow' '-Djavax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl')

# set options based on specific service passed, if recognized
case "$1" in
  master)  ACCUMULO_SERVICE_OPTS=("${ACCUMULO_MASTER_OPTS[@]}") ;;
  gc)      ACCUMULO_SERVICE_OPTS=("${ACCUMULO_GC_OPTS[@]}") ;;
  tserver) ACCUMULO_SERVICE_OPTS=("${ACCUMULO_TSERVER_OPTS[@]}") ;;
  monitor) ACCUMULO_SERVICE_OPTS=("${ACCUMULO_MONITOR_OPTS[@]}")
    CLASSPATH="/usr/share/accumulo/lib/:${CLASSPATH}"
    ;;
  logger)  ACCUMULO_SERVICE_OPTS=("${ACCUMULO_LOGGER_OPTS[@]}") ;;
  *)       ACCUMULO_SERVICE_OPTS=("${ACCUMULO_OTHER_OPTS[@]}") ;;
esac

# This is the main environment variable, holding all the java arguments for the process launch
# app isn't used for anything, but makes it easier to locate services quickly with ps/top/etc output
ACCUMULO_OPTS=("-Dapp=$1" "${ACCUMULO_GENERAL_OPTS[@]}" "${ACCUMULO_SERVICE_OPTS[@]}" "${ACCUMULO_SECURITY_OPTS[@]}" "-XX:OnOutOfMemoryError=${ACCUMULO_KILL_CMD}")

# Minimally, include the configuration directory in the classpath
CLASSPATH="${ACCUMULO_CONF_DIR}${ACCUMULO_CONF_DIR+:}${CLASSPATH}"
# Set ACCUMULO_HOME, as it's used read by the VFS classloader
ACCUMULO_HOME=${ACCUMULO_HOME:-$ACCUMULO_CONF_DIR}

# export any environment options that might be used by the jvm
export ACCUMULO_HOME ACCUMULO_CONF_DIR ACCUMULO_LOG_DIR MALLOC_ARENA_MAX