Example: tsdb.in

Note the changes to the Base of MapR installation section.

#!/bin/bash

set -e
me=`basename "$0"`
mydir=`dirname "$0"`
# Either:
#  abs_srcdir and abs_builddir are set: we're running in a dev tree
#  or pkgdatadir is set: we've been installed, we respect that.
abs_srcdir='@abs_srcdir@'
abs_builddir='@abs_builddir@'
pkgdatadir='@pkgdatadir@'
configdir='@configdir@'
# Either we've been installed and pkgdatadir exists, or we haven't been
# installed and abs_srcdir / abs_builddir aren't empty.
test -d "$pkgdatadir" || test -n "$abs_srcdir$abs_builddir" || {
  echo >&2 "$me: Uh-oh, \`$pkgdatadir' doesn't exist, is OpenTSDB properly installed?"
  exit 1
}

if test -n "$pkgdatadir"; then
  localdir="$pkgdatadir"
  for jar in "$pkgdatadir"/*.jar; do
    CLASSPATH="$CLASSPATH:$jar"
  done
  # Add pkgdatadir itself so we can find logback.xml
  CLASSPATH="$CLASSPATH:$pkgdatadir"

  if test -d "$pkgdatadir/bin"; then
    CLASSPATH="$CLASSPATH:$pkgdatadir/bin"
  fi

  if test -d "$pkgdatadir/lib"; then
    for jar in "$pkgdatadir"/lib/*.jar; do
      CLASSPATH="$CLASSPATH:$jar"
    done
  fi

  if test -n "$configdir" && test -d "$configdir"; then
    CLASSPATH="$CLASSPATH:$configdir"
  fi
else
  localdir="$abs_builddir"
  # If we're running out of the build tree, it's especially important that we
  # know exactly what jars we need to build the CLASSPATH.  Otherwise people
  # cannot easily pick up new dependencies as we might mix multiple versions
  # of the same dependencies on the CLASSPATH, which is bad.  Looking for a
  # specific version of each jar prevents this problem.
  # TODO(tsuna): Once we jarjar all the dependencies together, this will no
  # longer be an issue.  See issue #23.

  # Base of MapR installation
  BASEMAPR=${MAPR_HOME:-/opt/mapr}

  #add MapR specific asynchbase jar in classpath
  if test -d "$BASEMAPR/asynchbase"; then
    for jar in "$BASEMAPR"/asynchbase/asynchbase-*/*.jar; do
      if [[ `echo $jar | grep sources` != "" ]] || [[ `echo $jar | grep javadoc` != "" ]]; then
        continue
      fi
      CLASSPATH="$CLASSPATH:$jar"
     done
  fi

  for jar in `make -C "$abs_builddir" printdeps | sed '/third_party.*jar/!d'`; do
    if [[ `echo $jar | grep asynchbase` != "" ]]; then
      continue
    fi
    for dir in "$abs_builddir" "$abs_srcdir"; do
      test -f "$dir/$jar" && CLASSPATH="$CLASSPATH:$dir/$jar" && continue 2
    done
    echo >&2 "$me: error: Couldn't find \`$jar' either under \`$abs_builddir' or \`$abs_srcdir'."
    exit 2
  done
  # Add the src dir so we can find logback.xml
  CLASSPATH="$CLASSPATH:$abs_srcdir/src"
fi
# Remove any leading colon.
CLASSPATH="${CLASSPATH#:}"

# Add MapR hadoop jars to classpath
if test -d "$BASEMAPR/hadoop/hadoop-0.20.2/lib"; then
  # hadoop conf directory to beginning of classpath (for core-site.xml)
  CLASSPATH="$BASEMAPR/hadoop/hadoop-0.20.2/conf:$CLASSPATH"

  for jar in "$BASEMAPR"/hadoop/hadoop-0.20.2/lib/*.jar; do
    if [[ `echo $jar | grep slf4j` != "" ]]; then
      continue
    fi
    CLASSPATH="$CLASSPATH:$jar"
  done
fi

# MapR native library path
JVMARGS="${JVMARGS} -Djava.library.path=${BASEMAPR}/lib"

# TSD compactions are not required with M7
JVMARGS="${JVMARGS} -Dtsd.feature.compactions=false"

usage() {
  echo >&2 "usage: $me <command> [args]"
  echo 'Valid commands: fsck, import, mkmetric, query, tsd, scan, uid'
  exit 1
}

case $1 in
  (fsck)
    MAINCLASS=Fsck
    ;;
  (import)
    MAINCLASS=TextImporter
    ;;
  (mkmetric)
    shift
    set uid assign metrics "$@"
    MAINCLASS=UidManager
    ;;
  (query)
    MAINCLASS=CliQuery
    ;;
  (tsd)
    MAINCLASS=TSDMain
    ;;
  (scan)
    MAINCLASS=DumpSeries
    ;;
  (uid)
    MAINCLASS=UidManager
    ;;
  (*)
    echo >&2 "$me: error: unknown command '$1'"
    usage
    ;;
esac
shift

JAVA=${JAVA-'java'}
JVMARGS=${JVMARGS-'-enableassertions -enablesystemassertions'}
test -r "$localdir/tsdb.local" && . "$localdir/tsdb.local"
exec $JAVA $JVMARGS -classpath "$CLASSPATH" net.opentsdb.tools.$MAINCLASS "$@"