diff --git a/bin/logstash b/bin/logstash index ef2a5d2b70d..6b2642430d6 100755 --- a/bin/logstash +++ b/bin/logstash @@ -9,13 +9,9 @@ # See 'bin/logstash --help' for a list of commands. # # Supported environment variables: -# LS_JVM_OPTS="xxx" path to file with JVM options -# LS_JAVA_OPTS="xxx" to append extra options to the defaults JAVA_OPTS provided by logstash -# JAVA_OPTS="xxx" to *completely override* the default set of JAVA_OPTS provided by logstash +# LS_JAVA_OPTS="xxx" to append extra options to the JVM options provided by logstash # # Development environment variables: -# USE_RUBY=1 to force use the local "ruby" command to launch logstash instead of using the vendored JRuby -# USE_DRIP=1 to force use drip # DEBUG=1 to output debugging information unset CDPATH diff --git a/bin/logstash.lib.sh b/bin/logstash.lib.sh index 76aa335f5ef..4074481eb65 100755 --- a/bin/logstash.lib.sh +++ b/bin/logstash.lib.sh @@ -28,25 +28,23 @@ export LOGSTASH_HOME SINCEDB_DIR="${LOGSTASH_HOME}" export SINCEDB_DIR -# This block will iterate over the command-line args Logstash was started with -# It will find the argument _after_ --path.settings and use that to attempt -# to derive the location of an acceptable jvm.options file -# It will do nothing if this is not found. +# iterate over the command line args and look for the argument +# after --path.settings to see if the jvm.options file is in +# that path and set LS_JVM_OPTS accordingly # This fix is for #6379 -if [ -z "$LS_JVM_OPTS" ]; then - found=0 - for i in "$@"; do - if [ $found -eq 1 ]; then - if [ -r "${i}/jvm.options" ]; then - export LS_JVM_OPTS="${i}/jvm.options" - break - fi - fi - if [ "$i" = "--path.settings" ]; then - found=1 - fi - done -fi +unset LS_JVM_OPTS +found=0 +for i in "$@"; do + if [ $found -eq 1 ]; then + if [ -r "${i}/jvm.options" ]; then + export LS_JVM_OPTS="${i}/jvm.options" + break + fi + fi + if [ "$i" = "--path.settings" ]; then + found=1 + fi +done parse_jvm_options() { if [ -f "$1" ]; then @@ -55,26 +53,31 @@ parse_jvm_options() { } setup_java() { - if [ -z "$JAVACMD" ] ; then - if [ -n "$JAVA_HOME" ] ; then - JAVACMD="$JAVA_HOME/bin/java" - else - JAVACMD="java" - fi + # set the path to java into JAVACMD which will be picked up by JRuby to launch itself + if [ -x "$JAVA_HOME/bin/java" ]; then + JAVACMD="$JAVA_HOME/bin/java" + else + set +e + JAVACMD=`which java` + set -e fi - # Resolve full path to the java command. - if [ ! -f "$JAVACMD" ] ; then - JAVACMD="$(which $JAVACMD 2>/dev/null)" + if [ ! -x "$JAVACMD" ]; then + echo "could not find java; set JAVA_HOME or ensure java is in PATH" + exit 1 fi - if [ ! -x "$JAVACMD" ] ; then - echo "Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME." 1>&2 - exit 1 + # do not let JAVA_TOOL_OPTIONS slip in (as the JVM does by default) + if [ ! -z "$JAVA_TOOL_OPTIONS" ]; then + echo "warning: ignoring JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS" + unset JAVA_TOOL_OPTIONS fi - if [ "$JAVA_OPTS" ] ; then - echo "WARNING: Default JAVA_OPTS will be overridden by the JAVA_OPTS defined in the environment. Environment JAVA_OPTS are $JAVA_OPTS" 1>&2 + # JAVA_OPTS is not a built-in JVM mechanism but some people think it is so we + # warn them that we are not observing the value of $JAVA_OPTS + if [ ! -z "$JAVA_OPTS" ]; then + echo -n "warning: ignoring JAVA_OPTS=$JAVA_OPTS; " + echo "pass JVM parameters via LS_JAVA_OPTS" fi # Set a default GC log file for use by jvm.options _before_ it's called. @@ -94,50 +97,15 @@ setup_java() { fi done fi - # use the defaults, first, then override with anything provided + # then override with anything provided LS_JAVA_OPTS="$(parse_jvm_options "$LS_JVM_OPTS") $LS_JAVA_OPTS" + JAVA_OPTS=$LS_JAVA_OPTS - if [ "$LS_JAVA_OPTS" ] ; then - # The client set the variable LS_JAVA_OPTS, choosing his own - # set of java opts. - JAVA_OPTS="$JAVA_OPTS $LS_JAVA_OPTS" - fi - + # jruby launcher uses JAVACMD as its java executable and JAVA_OPTS as the JVM options export JAVACMD export JAVA_OPTS } -setup_drip() { - if [ -z "$DRIP_JAVACMD" ] ; then - JAVACMD="drip" - fi - - # resolve full path to the drip command. - if [ ! -f "$JAVACMD" ] ; then - JAVACMD="$(which $JAVACMD 2>/dev/null)" - fi - - if [ ! -x "$JAVACMD" ] ; then - echo "Could not find executable drip binary. Please install drip in your PATH" - exit 1 - fi - - # faster JRuby startup options https://github.com/jruby/jruby/wiki/Improving-startup-time - # since we are using drip to speed up, we may as well throw these in also - if [ "$USE_RUBY" = "1" ] ; then - export JRUBY_OPTS="$JRUBY_OPTS -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify" - else - if [ -z "$JAVA_OPTS" ] ; then - LS_JAVA_OPTS="$LS_JAVA_OPTS -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -noverify" - else - JAVA_OPTS="$JAVA_OPTS -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -noverify" - fi - fi - export JAVACMD - export DRIP_INIT_CLASS="org.jruby.main.DripMain" - export DRIP_INIT="" -} - setup_vendored_jruby() { JRUBY_BIN="${LOGSTASH_HOME}/vendor/jruby/bin/jruby" @@ -147,51 +115,16 @@ setup_vendored_jruby() { echo "If you are a developer, please run 'rake bootstrap'. Running 'rake' requires the 'ruby' program be available." exit 1 fi - VENDORED_JRUBY=1 -} - -setup_ruby() { - RUBYCMD="ruby" - VENDORED_JRUBY= } setup() { - # first check if we want to use drip, which can be used in vendored jruby mode - # and also when setting USE_RUBY=1 if the ruby interpreter is in fact jruby - if [ "$JAVACMD" ] ; then - if [ "$(basename $JAVACMD)" = "drip" ] ; then - DRIP_JAVACMD=1 - USE_DRIP=1 - fi - fi - if [ "$USE_DRIP" = "1" ] ; then - setup_drip - fi - - if [ "$USE_RUBY" = "1" ] ; then - setup_ruby - else - setup_java - setup_vendored_jruby - fi + setup_java + setup_vendored_jruby } ruby_exec() { - if [ -z "$VENDORED_JRUBY" ] ; then - - # $VENDORED_JRUBY is empty so use the local "ruby" command - - if [ "$DEBUG" ] ; then - echo "DEBUG: exec ${RUBYCMD} $@" - fi - exec "${RUBYCMD}" "$@" - else - - # $VENDORED_JRUBY is non-empty so use the vendored JRuby - - if [ "$DEBUG" ] ; then - echo "DEBUG: exec ${JRUBY_BIN} $@" - fi - exec "${JRUBY_BIN}" "$@" + if [ "$DEBUG" ] ; then + echo "DEBUG: exec ${JRUBY_BIN} $@" fi + exec "${JRUBY_BIN}" "$@" } diff --git a/dripmain.rb b/dripmain.rb deleted file mode 100644 index 3631e39b66e..00000000000 --- a/dripmain.rb +++ /dev/null @@ -1,24 +0,0 @@ -# dripmain.rb is called by org.jruby.main.DripMain to further warm the JVM with any preloading -# that we can do to speedup future startup using drip. - -require_relative "lib/bootstrap/environment" -LogStash::Bundler.setup!({:without => [:build]}) -require "logstash-core" - -# typical required gems and libs -require "logstash/environment" -LogStash::Environment.load_locale! - -require "cabin" -require "stud/trap" -require "stud/task" -require "clamp" -require "rspec" -require "rspec/core/runner" - -require "logstash/namespace" -require "logstash/agent" -require "logstash/util" -require "logstash/errors" -require "logstash/pipeline" -require "logstash/plugin"