Skip to content

Commit

Permalink
Update existing packaging to use /usr/lib/logstash
Browse files Browse the repository at this point in the history
Update after-install scripts

Use /usr/lib/logstash instead of /opt/logstash

More revisions.

Using `/usr/share/logstash` instead of `/usr/lib/logstash`

Track these new files

More work in progress.

Proper arg parsing obtained

WIP: Use jvm.options like ES

Remove facter dependency

Due to an update from @jordansissel on pleaserun, facter is no longer necessary

Revert Gemfile to proper version

Latest work in progress.

I added a simple test to logstash.lib.sh to catch empty strings in java options.

Added `startup.options`, and touched up `jvm.options`

Edited the package scripts to make things play nice with new paths.

Tweaked `system-install` to allow users to provide their own `startup.options` file.

Patch up merge failure

Changes to work with the new logstash.yml

Add fpm dependency (build fails without it)

Fix missing gems in Gemfile

Don't know how these got lost

Use /etc/logstash for configuration in packages

Update the instructions/documentation for...

...startup.options
  • Loading branch information
untergeek committed May 20, 2016
1 parent bdddab9 commit 4bc2335
Show file tree
Hide file tree
Showing 25 changed files with 525 additions and 672 deletions.
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ gem "rubyzip", "~> 1.1.7", :group => :build
gem "gems", "~> 0.8.3", :group => :build
gem "rack-test", :require => "rack/test", :group => :development
gem "flores", "~> 0.0.6", :group => :development
gem "pleaserun"
gem "mustache"
gem "clamp"
2 changes: 1 addition & 1 deletion bin/logstash
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# See 'bin/logstash help' for a list of commands.
#
# Supported environment variables:
# LS_HEAP_SIZE="xxx" size for the -Xmx${LS_HEAP_SIZE} maximum Java heap size option, default is "1g"
# 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 defauls set of JAVA_OPTS provided by logstash
#
Expand Down
64 changes: 29 additions & 35 deletions bin/logstash.lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ fi
LOGSTASH_HOME=$(cd `dirname $SOURCEPATH`/..; pwd)
export LOGSTASH_HOME

# Defaults you can override with environment variables
LS_HEAP_SIZE="${LS_HEAP_SIZE:=1g}"
parse_jvm_options() {
if [ -f "$1" ]; then
echo "$(grep "^-" "$1" | tr '\n' ' ')"
fi
}

setup_java() {
if [ -z "$JAVACMD" ] ; then
Expand All @@ -50,45 +53,34 @@ setup_java() {

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"
fi

# Set a default GC log file for use by jvm.options _before_ it's called.
if [ -z "$LS_GC_LOG_FILE" ] ; then
LS_GC_LOG_FILE="./logstash-gc.log"
fi

JAVA_OPTS="$JAVA_OPTS -XX:CMSInitiatingOccupancyFraction=75"
JAVA_OPTS="$JAVA_OPTS -XX:+UseCMSInitiatingOccupancyOnly"
# Causes the JVM to dump its heap on OutOfMemory.
JAVA_OPTS="$JAVA_OPTS -XX:+HeapDumpOnOutOfMemoryError"
# The path to the heap dump location
# This variable needs to be isolated since it may contain spaces
HEAP_DUMP_PATH="-XX:HeapDumpPath=${LOGSTASH_HOME}/heapdump.hprof"
# Set the initial JVM options from the jvm.options file. Look in
# /etc/logstash first, and break if that file is found readable there.
if [ -z "$LS_JVM_OPTS" ]; then
for jvm_options in /etc/logstash/jvm.options \
"$LOGSTASH_HOME"/config/jvm.options;
do
if [ -r "$jvm_options" ]; then
LS_JVM_OPTS=$jvm_options
break
fi
done
fi
# use the defaults, first, then override with anything provided
LS_JAVA_OPTS="$(parse_jvm_options "$LS_JVM_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

if [ "$LS_HEAP_SIZE" ] ; then
JAVA_OPTS="$JAVA_OPTS -Xmx${LS_HEAP_SIZE}"
fi

if [ "$LS_USE_GC_LOGGING" ] ; then
if [ -z "$LS_GC_LOG_FILE" ] ; then
LS_GC_LOG_FILE="./logstash-gc.log"
fi
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:${LS_GC_LOG_FILE}"
echo "Writing garbage collection logs to ${LS_GC_LOG_FILE}"
fi

export JAVACMD
export JAVA_OPTS
}
Expand Down Expand Up @@ -140,7 +132,9 @@ setup_ruby() {
jruby_opts() {
printf "%s" "--1.9"
for i in $JAVA_OPTS ; do
printf "%s" " -J$i"
if [ "x$i" != "x" ] && [ "x$i" != "x " ]; then
printf "%s" " -J$i"
fi
done
}

Expand Down Expand Up @@ -179,8 +173,8 @@ ruby_exec() {
# $VENDORED_JRUBY is non-empty so use the vendored JRuby

if [ "$DEBUG" ] ; then
echo "DEBUG: exec ${JRUBY_BIN} $(jruby_opts) "-J$HEAP_DUMP_PATH" $@"
echo "DEBUG: exec ${JRUBY_BIN} $(jruby_opts) $@"
fi
exec "${JRUBY_BIN}" $(jruby_opts) "-J$HEAP_DUMP_PATH" "$@"
exec "${JRUBY_BIN}" $(jruby_opts) "$@"
fi
}
41 changes: 41 additions & 0 deletions bin/system-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

unset CDPATH
. "$(cd `dirname $0`/..; pwd)/bin/logstash.lib.sh"
setup

if [ -z "$1" ]; then
[ -r ${LOGSTASH_HOME}/config/startup.options ] && . ${LOGSTASH_HOME}/config/startup.options
[ -r /etc/logstash/startup.options ] && . /etc/logstash/startup.options
else
if [ -r $1 ]; then
echo "Using provided startup.options file: ${1}"
. $1
else
echo "$1 is not a file path"
fi
fi

# bin/logstash-plugin is a short lived ruby script thus we can use aggressive "faster starting JRuby options"
# see https://github.com/jruby/jruby/wiki/Improving-startup-time
export JRUBY_OPTS="$JRUBY_OPTS -J-XX:+TieredCompilation -J-XX:TieredStopAtLevel=1 -J-noverify -X-C -Xcompile.invokedynamic=false"

tempfile=$(mktemp)
if [ "x${PRESTART}" == "x" ]; then
opts=("--log" "$tempfile" "--overwrite" "--install" "--name" "${INIT_NAME}" "--user" "${LS_USER}" "--group" "${LS_GROUP}" "--description" "${INIT_DESCRIPTION}" "--nice" "${LS_NICE}" "--limit-open-files" "${LS_OPEN_FILES}")
else
opts=("--log" "$tempfile" "--overwrite" "--install" "--name" "${INIT_NAME}" "--user" "${LS_USER}" "--group" "${LS_GROUP}" "--description" "${INIT_DESCRIPTION}" "--nice" "${LS_NICE}" "--limit-open-files" "${LS_OPEN_FILES}" "--prestart" "${PRESTART}")
fi

program="$(cd `dirname $0`/..; pwd)/bin/logstash"

capture="$(ruby_exec "${LOGSTASH_HOME}/lib/systeminstall/pleasewrap.rb" "${opts[@]}" ${program} ${LS_OPTS})"
exit_code=$?

if [ $exit_code -ne 0 ]; then
cat $tempfile
echo "Unable to install system startup script for Logstash."
else
echo "Successfully created system startup script for Logstash"
fi
rm $tempfile
74 changes: 74 additions & 0 deletions config/jvm.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
## JVM configuration

# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

-Xms256m
-Xmx1g

################################################################
## Expert settings
################################################################
##
## All settings below this section are considered
## expert settings. Don't tamper with them unless
## you understand what you are doing
##
################################################################

## GC configuration
-XX:+UseParNewGC
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly

## optimizations

# disable calls to System#gc
-XX:+DisableExplicitGC

## Locale
# Set the locale language
#-Duser.language=en

# Set the locale country
#-Duser.country=US

# Set the locale variant, if any
#-Duser.variant=

## Basic settings

# set the I/O temp directory
-Djava.io.tmpdir=$HOME

# set to headless, just in case
-Djava.awt.headless=true

# ensure UTF-8 encoding by default (e.g. filenames)
-Dfile.encoding=UTF-8

# use our provided JNA always versus the system one
#-Djna.nosys=true

## heap dumps

# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX:+HeapDumpOnOutOfMemoryError

# specify an alternative path for heap dumps
# ensure the directory exists and has sufficient space
#-XX:HeapDumpPath=${LOGSTASH_HOME}/heapdump.hprof

## GC logging
#-XX:+PrintGCDetails
#-XX:+PrintGCTimeStamps
#-XX:+PrintGCDateStamps
#-XX:+PrintClassHistogram
#-XX:+PrintTenuringDistribution
#-XX:+PrintGCApplicationStoppedTime

# log GC status to a file with time stamps
# ensure the directory exists
#-Xloggc:${LS_GC_LOG_FILE}
57 changes: 57 additions & 0 deletions config/startup.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
################################################################################
# These settings are ONLY used by $LS_HOME/bin/system-install to create a custom
# startup script for Logstash. It should automagically use the init system
# (systemd, upstart, sysv, etc.) that your Linux distribution uses.
#
# After changing anything here, you need to re-run $LS_HOME/bin/system-install
# as root to push the changes to the init script.
################################################################################

# Override Java location
JAVACMD=/usr/bin/java

# Set a home directory
LS_HOME=/usr/share/logstash

# logstash settings directory, the path which contains logstash.yml
LS_SETTINGS_DIR="${LS_HOME}/config"

# Arguments to pass to logstash
LS_OPTS="--path.settings ${LS_SETTINGS_DIR}"

# Arguments to pass to java
LS_JAVA_OPTS=""

# pidfiles aren't used the same way for upstart and systemd; this is for sysv users.
LS_PIDFILE=/var/run/logstash.pid

# user and group id to be invoked as
LS_USER=logstash
LS_GROUP=logstash

# Enable GC logging by uncommenting the appropriate lines in the GC logging
# section in jvm.options
LS_GC_LOG_FILE=/var/log/logstash/gc.log

# Open file limit
LS_OPEN_FILES=16384

# Nice level
LS_NICE=19

# If this is set to 1, then when `stop` is called, if the process has
# not exited within a reasonable time, SIGKILL will be sent next.
# The default behavior is to simply log a message "program stop failed; still running"
#KILL_ON_STOP_TIMEOUT=0

# Change these to have the init script named and described differently
# This is useful when running multiple instances of Logstash on the same
# physical box or vm
INIT_NAME="logstash"
INIT_DESCRIPTION="logstash"

# If you need to run a command or script before launching Logstash, put it
# between the lines beginning with `read` and `EOM`, and uncomment those lines.
###
## read -r -d '' PRESTART << EOM
## EOM
12 changes: 12 additions & 0 deletions lib/systeminstall/pleasewrap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# encoding: utf-8
$LOAD_PATH.unshift(File.expand_path(File.join(__FILE__, "..", "..")))

require "bootstrap/environment"

ENV["GEM_HOME"] = ENV["GEM_PATH"] = LogStash::Environment.logstash_gem_home
Gem.use_paths(LogStash::Environment.logstash_gem_home)

#libdir = File.expand_path("../lib", File.dirname(__FILE__))
#$LOAD_PATH << libdir if File.exist?(File.join(libdir, "pleaserun", "cli.rb"))
require "pleaserun/cli"
exit(PleaseRun::CLI.run || 0)
5 changes: 3 additions & 2 deletions pkg/centos/after-install.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/sbin/chkconfig --add logstash
# /sbin/chkconfig --add logstash

chown -R logstash:logstash /opt/logstash
chown -R logstash:logstash /usr/share/logstash
chown logstash /var/log/logstash
chown logstash:logstash /var/lib/logstash
chmod 0644 /etc/logrotate.d/logstash
/usr/share/logstash/bin/system-install /etc/logstash/startup.options
2 changes: 1 addition & 1 deletion pkg/centos/before-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ fi

# create logstash user
if ! getent passwd logstash >/dev/null; then
useradd -r -g logstash -d /opt/logstash \
useradd -r -g logstash -d /usr/share/logstash \
-s /sbin/nologin -c "logstash" logstash
fi
16 changes: 14 additions & 2 deletions pkg/centos/before-remove.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
if [ $1 -eq 0 ]; then
/sbin/service logstash stop >/dev/null 2>&1 || true
/sbin/chkconfig --del logstash
if [ ! -f "/etc/systemd/system/logstash.service" ]; then
/sbin/stop logstash >/dev/null 2>&1 || true
/sbin/service logstash stop >/dev/null 2>&1 || true
/sbin/chkconfig --del logstash
else
systemctl stop logstash >/dev/null 2>&1 || true
if [ -f "/etc/systemd/system/logstash-prestart.sh" ]; then
rm /etc/systemd/system/logstash-prestart.sh
fi

if [ -f "/etc/systemd/system/logstash.service" ]; then
rm /etc/systemd/system/logstash.service
fi
fi
if getent passwd logstash >/dev/null ; then
userdel logstash
fi
Expand Down
3 changes: 2 additions & 1 deletion pkg/debian/after-install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/sh

chown -R logstash:logstash /opt/logstash
chown -R logstash:logstash /usr/share/logstash
chown logstash /var/log/logstash
chown logstash:logstash /var/lib/logstash
chmod 755 /etc/logstash
chmod 0644 /etc/logrotate.d/logstash
/usr/share/logstash/bin/system-install /etc/logstash/startup.options
2 changes: 1 addition & 1 deletion pkg/debian/before-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ fi

# create logstash user
if ! getent passwd logstash >/dev/null; then
useradd -M -r -g logstash -d /var/lib/logstash \
useradd -M -r -g logstash -d /usr/share/logstash \
-s /usr/sbin/nologin -c "LogStash Service User" logstash
fi
14 changes: 12 additions & 2 deletions pkg/debian/before-remove.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
#!/bin/sh

if [ $1 = "remove" ]; then
service logstash stop >/dev/null 2>&1 || true
if [ ! -f "/etc/systemd/system/logstash.service" ]; then
service logstash stop >/dev/null 2>&1 || true
else
systemctl stop logstash >/dev/null 2>&1 || true
if [ -f "/etc/systemd/system/logstash-prestart.sh" ]; then
rm /etc/systemd/system/logstash-prestart.sh
fi

if [ -f "/etc/systemd/system/logstash.service" ]; then
rm /etc/systemd/system/logstash.service
fi
fi
if getent passwd logstash >/dev/null ; then
userdel logstash
fi

if getent group logstash >/dev/null ; then
if getent group logstash > /dev/null ; then
groupdel logstash
fi
fi
Loading

0 comments on commit 4bc2335

Please sign in to comment.