#!/bin/sh
# Run logstash from source
#
# This is most useful when done from a git checkout.
#
# Usage:
#     bin/logstash <command> [arguments]
#
# See 'bin/logstash help' for a list of commands.
#
# NOTE: One extra command is available 'deps'
# The 'deps' command will install dependencies for logstash.
#
# If you do not have ruby installed, you can set "USE_JRUBY=1"
# in your environment and this script will download and use
# a release of JRuby for you.

# Defaults you can override with environment variables
LS_HEAP_SIZE="${LS_HEAP_SIZE:=500m}"

unset CDPATH
basedir=$(cd `dirname $0`/..; pwd)
. ${basedir}/bin/logstash.lib.sh

setup

# Export these so that they can be picked up by file input (and others?).
export HOME SINCEDB_DIR

case $1 in
  deps) install_deps ;;
  env) env "$@" ;;
  -*) 
    # is the first argument a flag? If so, assume 'agent'
    program="$basedir/lib/logstash/runner.rb"
    exec $RUBYCMD -I$RUBYLIB "$program" agent "$@"
    ;;
  *)
    program="$basedir/lib/logstash/runner.rb"
    exec $RUBYCMD -I$RUBYLIB "$program" "$@"
    ;;
esac
