-
Notifications
You must be signed in to change notification settings - Fork 3.5k
/
Copy pathlogstash.lib.sh
executable file
·154 lines (129 loc) · 4.01 KB
/
logstash.lib.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
unset CDPATH
LOGSTASH_HOME=$(cd `dirname $0`/..; pwd)
export LOGSTASH_HOME
# Defaults you can override with environment variables
LS_HEAP_SIZE="${LS_HEAP_SIZE:=500m}"
setup_java() {
if [ -z "$JAVACMD" ] ; then
if [ -n "$JAVA_HOME" ] ; then
JAVACMD="$JAVA_HOME/bin/java"
else
JAVACMD="java"
fi
fi
# Resolve full path to the java command.
if [ ! -f "$JAVACMD" ] ; then
JAVACMD=$(which $JAVACMD 2>/dev/null)
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
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
else
# There are no JAVA_OPTS set from the client, we set a predefined
# set of options that think are good in general
JAVA_OPTS="-XX:+UseParNewGC"
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC"
JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"
JAVA_OPTS="$JAVA_OPTS -XX:CMSInitiatingOccupancyFraction=75"
JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSInitiatingOccupancyOnly"
fi
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
if [ "$LS_HEAP_SIZE" ] ; then
JAVA_OPTS="$JAVA_OPTS -Xmx${LS_HEAP_SIZE}"
fi
if [ "$LS_USE_GC_LOGGING" ] ; then
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCDetails"
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCTimeStamps"
JAVA_OPTS="$JAVA_OPTS -XX:+PrintClassHistogram"
JAVA_OPTS="$JAVA_OPTS -XX:+PrintTenuringDistribution"
JAVA_OPTS="$JAVA_OPTS -XX:+PrintGCApplicationStoppedTime"
JAVA_OPTS="$JAVA_OPTS -Xloggc:./logstash-gc.log"
echo "Writing garbage collection logs to ./logstash-gc.log"
fi
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
JAVA_OPTS="$JAVA_OPTS -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -noverify"
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"
if [ ! -f "${JRUBY_BIN}" ] ; then
echo "Unable to find JRuby."
echo "If you are a user, this is a bug."
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=
}
jruby_opts() {
printf "%s" "--1.9"
for i in $JAVA_OPTS ; do
printf "%s" " -J$i"
done
}
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 interpretor 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
}
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} $(jruby_opts) $@"
fi
exec "${JRUBY_BIN}" $(jruby_opts) "$@"
fi
}