Skip to content

Commit

Permalink
refactor linux launch scripts per elastic#8261
Browse files Browse the repository at this point in the history
remove dripmain.rb
  • Loading branch information
colinsurprenant committed Sep 19, 2017
1 parent 2c36246 commit 0e3b9a3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 139 deletions.
6 changes: 1 addition & 5 deletions bin/logstash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
153 changes: 43 additions & 110 deletions bin/logstash.lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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"

Expand All @@ -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}" "$@"
}
24 changes: 0 additions & 24 deletions dripmain.rb

This file was deleted.

0 comments on commit 0e3b9a3

Please sign in to comment.