Merge pull request #680 from sbagmeijer/master

Update logstash.spec
This commit is contained in:
Nick Ethier 2013-11-06 17:12:52 -08:00
commit 692dd040d8
5 changed files with 309 additions and 187 deletions

View file

@ -0,0 +1,26 @@
### THIS IS A EXAMPLE CONFIG SO LOGSTASH WILL RUN ###
### PLEASE UPDATE THIS TO WHATEVER YOU WANT TO USE ###
input {
syslog {
type => syslog
port => 5544
}
}
filter {
mutate {
add_field => [ "hostip", "%{host}" ]
}
dns {
reverse => [ "host" ]
action => "replace"
}
}
output {
elasticsearch {
host => "localhost"
}
}

View file

@ -1,157 +1,80 @@
#! /bin/sh
#
# /etc/rc.d/init.d/logstash
#
# Starts Logstash as a daemon
#
# chkconfig: 2345 20 80
# description: Starts Logstash as a daemon
#!/bin/bash
# chkconfig: - 80 15
### BEGIN INIT INFO
# Provides: logstash
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: S 0 1 6
# Short-Description: Logstash
# Description: Starts Logstash as a daemon.
# Required-Start: $all
# Required-Stop: $all
# Default-Start:
# Default-Stop: 0 1 6
# Short-Description: Starts logstash
# Description: Logstash agent
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=logstash
DESC="Logstash Daemon"
DEFAULT=/etc/sysconfig/$NAME
NAME=@@@NAME@@@
if [ `id -u` -ne 0 ]; then
echo "You need root privileges to run this script"
exit 1
fi
[ -f /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
# The following variables can be overwritten in $DEFAULT
LOGSTASH_USER=${NAME}
DAEMON="@@@DAEMON@@@/${NAME}"
SERVICE=agent
export JAVA_HOME=/usr
PID_FILE=${PIDFILE:-@@@PIDDIR@@@/${NAME}.pid}
LOCK_FILE=${LOCKFILE:-@@@LOCKFILE@@@}
LOG_FILE=${LOGFILE:-@@@LOGDIR@@@/${NAME}.log}
# Directory where the logstash all in one jar lives
LS_HOME=/usr/share/logstash
LOGSTASH_PATH_CONF=${LOGSTASH_PATH_CONF:-@@@CONFDIR@@@}
LOGSTASH_LOGLEVEL=${LOGSTASH_LOGLEVEL:-"warn"}
# Additional Java OPTS
LS_JAVA_OPTS="-Xmx256m -Djava.io.tmpdir=$LS_HOME/tmp"
DAEMON_OPTS="\
-P ${PID_FILE} \
-l ${LOG_FILE} \
-f ${LOGSTASH_PATH_CONF} \
-v $LOGSTASH_LOGLEVEL \
"
# logstash log directory
LOG_DIR=/var/log/logstash
# logstash configuration directory
CONF_DIR=/etc/logstash/conf.d
# logstash log file
LOG_FILE=$LOG_DIR/$NAME.log
# Open File limit
OPEN_FILES=2048
# Nice level
NICE=19
# Filter threads
FILTER_THREADS=1
# End of variables that can be overwritten in $DEFAULT
if [ -f "$DEFAULT" ]; then
. "$DEFAULT"
fi
# Define other required variables
PID_FILE=/var/run/$NAME.pid
JAVA=`which java`
JAR="${LS_HOME}/logstash.jar"
ARGS="${LS_JAVA_OPTS} -jar ${JAR} agent --config ${CONF_DIR} --log ${LOG_FILE} -w ${FILTER_THREADS}"
is_true() {
if [ "x$1" = "xtrue" -o "x$1" = "xyes" -o "x$1" = "x1" ] ; then
return 0
else
return 1
fi
}
#
# Function that starts the daemon/service
#
do_start()
{
if ! is_true "$START" ; then
echo "logstash not configured to start, please edit $DEFAULT to enable"
exit 0
fi
if [ -z "$JAVA" ]; then
echo "no JDK found - $JAVA"
exit 1
fi
if ! test -e "${JAR}"; then
echo "Daemon $DAEMON doesn't exist"
exit 1
fi
if pidofproc -p "$PID_FILE" >/dev/null; then
failure
exit 99
fi
ulimit -n $OPEN_FILES
cd $LS_HOME
$JAVA $ARGS > /dev/null 1>&1 &
RETVAL=$?
local PID=`pgrep -f "${DAEMON} ${ARGS}"`
echo $PID > $PID_FILE
success
}
#
# Function that stops the daemon/service
#
do_stop()
{
killproc -p $PID_FILE $DAEMON
start() {
echo -n $"Starting ${NAME}: "
export JAVA_OPTS="$JAVA_OPTS $LOGSTASH_JAVA_OPTS"
daemon --pidfile=${PID_FILE} --user $LOGSTASH_USER $DAEMON $SERVICE $DAEMON_OPTS
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${PID_FILE}
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
return $RETVAL
}
stop() {
echo -n $"Stopping ${NAME}: "
killproc -p ${PID_FILE} -d 10 $DAEMON
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${LOCK_FILE} ${PID_FILE}
return $RETVAL
}
case "$1" in
start)
echo -n "Starting $DESC: "
do_start
touch /var/lock/subsys/logstash/$NAME
start
;;
stop)
echo -n "Stopping $DESC: "
do_stop
rm /var/lock/subsys/logstash/$NAME
;;
restart|reload)
echo -n "Restarting $DESC: "
do_stop
do_start
stop
;;
status)
echo -n "$DESC"
status -p $PID_FILE
status -p ${PID_FILE} $DAEMON
RETVAL=$?
;;
restart|force-reload)
stop
start
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
exit 3
N=/etc/init.d/${NAME}
echo "Usage: $N {start|stop|restart|force-reload}" >&2
RETVAL=2
;;
esac
echo
exit 0
exit $RETVAL

View file

@ -1 +1,3 @@
START=false
#LOGSTASH_LOGFILE=@@@LOGDIR@@@/@@@NAME@@@.log
#LOGSTASH_PATH_CONF=@@@CONFDIR@@@
#LOGSTASH_JAVA_OPTS="-Djava.io.tmpdir=/opt/@@@NAME@@@/tmp"

View file

@ -0,0 +1,105 @@
#!/bin/sh
SCRIPT=$0
if [ -x "$JAVA_HOME/bin/java" ]; then
JAVA=$JAVA_HOME/bin/java
else
JAVA=`which java`
fi
LOGSTASH_JAR="@@@JARPATH@@@/@@@NAME@@@.jar"
if [ ! -f $LOGSTASH_JAR ]
then
echo "jar file is not found."
exit 99
fi
function usage() {
echo "Usage: ${SCRIPT} SERVICE OPTIONS"
echo " SERVICE: agent, web"
echo " OPTIONS:"
echo -e " -f, --config CONFIGFILE (required)\tLoad the logstash config from a specific file or directory."
echo -e " \t\tIf a direcory is given instead of a file, all files in that directory will be concatonated in lexicographical order and then parsed as a single config file."
echo -e " -P, --pidfile PIDFILE\t\tPID file path."
echo -e " -l, --logfile LOGFILE\t\tLogfile path."
echo -e " -v, --verbose [info, debug]\t\tEnables more verbose logging"
}
function run_service() {
service=$1
config=$2
pidfile=$3
logfile=$4
verbose=$5
if [ "x$logfile" == "x" ]; then
exec "$JAVA" $JAVA_OPTS -jar $LOGSTASH_JAR $service $verbose -f "$config" &
rs=$?
else
exec "$JAVA" $JAVA_OPTS -jar $LOGSTASH_JAR $service $verbose -f "$config" -l "$logfile" 2>&1 >> $logfile &
rs=$?
[ $rs -eq 0 -a "x$pidfile" != "x" ] && printf '%d' $! > "$pidfile"
fi
return $rs
}
service=$1; shift
if [ "${service}" != "agent" -a "${service}" != "web" ]
then
echo "ERROR: no such service \`${service}'. Available services are: agent, web"
usage
exit 99
fi
while test $# -gt 0
do
case "$1" in
-V | --version )
"$JAVA" -jar $LOGSTASH_JAR --version
exit 0
;;
-f | --config )
config="$2"
if [ ! -f "$config" -a ! -d "$config" ]; then
echo "ERROR: config file or directory \`$config' does not exist."
usage
exit 1
fi
shift 2
;;
-P | --pidfile )
pidfile="$2"
shift 2
;;
-l | --logfile )
logfile="$2"
shift 2
;;
-v | --verbose )
if [ "$2" == "debug" ]; then
verbose="-vv"
elif [ "$2" == "info" ]; then
verbose="-v"
fi
shift 2
;;
-h | --help )
usage
exit 0
;;
* )
break
esac
done
if [ "x$config" == "x" ]; then
echo "ERROR: config file is required."
usage
exit 1
fi
run_service "$service" "$config" "$pidfile" "$logfile" "$verbose"
exit $?

View file

@ -1,63 +1,92 @@
# do not repack jar files
%define __os_install_post %{nil}
%define __jar_repack %{nil}
# do not build debug packages
%define debug_package %{nil}
%define base_install_dir /usr/share/%{name}
%define debug_package %{nil}_bindir}
%define base_install_dir %{_javadir}{%name}
%global bindir %{_bindir}
%global confdir %{_sysconfdir}/%{name}
%global jarpath %{_javadir}
%global lockfile %{_localstatedir}/lock/subsys/%{name}
%global logdir %{_localstatedir}/log/%{name}
%global piddir %{_localstatedir}/run/%{name}
%global sysconfigdir %{_sysconfdir}/sysconfig
Name: logstash
Version: 1.1.9
Version: 1.2.2
Release: 2%{?dist}
Summary: Logstash is a tool for managing events and logs.
Summary: A tool for managing events and logs
Group: System Environment/Daemons
License: Apache License, Version 2.0
License: ASL 2.0
URL: http://logstash.net
Source0: https://logstash.objects.dreamhost.com/release/%{name}-%{version}-monolithic.jar
Source1: logstash.init
Source0: https://logstash.objects.dreamhost.com/release/%{name}-%{version}-flatjar.jar
Source1: logstash.wrapper
Source2: logstash.logrotate
Source3: logstash.sysconfig
Source3: logstash.init
Source4: logstash.sysconfig
Source5: logstash.conf
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildArch: noarch
BuildArch: x86_64 i386 i686
Requires: jre >= 1.6.0
Requires: java
Requires: jpackage-utils
Requires(post): chkconfig initscripts
Requires(pre): chkconfig initscripts
Requires(pre): shadow-utils
%description
Logstash is a tool for managing events and logs
A tool for managing events and logs.
%prep
true
%build
true
%install
rm -rf $RPM_BUILD_ROOT
%{__mkdir} -p %{buildroot}%{base_install_dir}
%{__install} -m 755 %{SOURCE0} %{buildroot}%{base_install_dir}/logstash.jar
# JAR file
%{__mkdir} -p %{buildroot}%{_javadir}
%{__install} -p -m 644 %{SOURCE0} %{buildroot}%{jarpath}/%{name}.jar
# plugins & patterns
%{__mkdir} -p %{buildroot}%{base_install_dir}/plugins
%{__mkdir} -p %{buildroot}%{_sysconfdir}/%{name}/patterns
# Config
%{__mkdir} -p %{buildroot}%{confdir}
%{__install} -m 644 %{SOURCE5} %{buildroot}%{confdir}/%{name}.conf
# logs
%{__mkdir} -p %{buildroot}%{_localstatedir}/log/%{name}
%{__install} -D -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/logrotate.d/logstash
# Wrapper script
%{__mkdir} -p %{buildroot}%{_bindir}
%{__install} -m 755 %{SOURCE1} %{buildroot}%{bindir}/%{name}
%{__sed} -i \
-e "s|@@@NAME@@@|%{name}|g" \
-e "s|@@@JARPATH@@@|%{jarpath}|g" \
%{buildroot}%{bindir}/%{name}
# Logs
%{__mkdir} -p %{buildroot}%{logdir}
%{__install} -D -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/logrotate.d/%{name}
# Misc
%{__mkdir} -p %{buildroot}%{piddir}
# sysconfig and init
%{__mkdir} -p %{buildroot}%{_sysconfdir}/rc.d/init.d
%{__mkdir} -p %{buildroot}%{_initddir}
%{__mkdir} -p %{buildroot}%{_sysconfdir}/sysconfig
%{__install} -m 755 %{SOURCE1} %{buildroot}%{_sysconfdir}/rc.d/init.d/logstash
%{__install} -m 644 %{SOURCE3} %{buildroot}%{_sysconfdir}/sysconfig/logstash
%{__install} -m 755 %{SOURCE3} %{buildroot}%{_initddir}/%{name}
%{__install} -m 644 %{SOURCE4} %{buildroot}%{sysconfigdir}/%{name}
%{__mkdir} -p %{buildroot}%{_localstatedir}/run/logstash
%{__mkdir} -p %{buildroot}%{_localstatedir}/lock/subsys/logstash
%{__mkdir} -p %{buildroot}%{base_install_dir}/tmp
%{__sed} -i \
-e "s|@@@NAME@@@|%{name}|g" \
-e "s|@@@DAEMON@@@|%{bindir}|g" \
-e "s|@@@CONFDIR@@@|%{confdir}|g" \
-e "s|@@@LOCKFILE@@@|%{lockfile}|g" \
-e "s|@@@LOGDIR@@@|%{logdir}|g" \
-e "s|@@@PIDDIR@@@|%{piddir}|g" \
%{buildroot}%{_initddir}/%{name}
%{__sed} -i \
-e "s|@@@NAME@@@|%{name}|g" \
-e "s|@@@CONFDIR@@@|%{confdir}|g" \
-e "s|@@@LOGDIR@@@|%{logdir}|g" \
-e "s|@@@PLUGINDIR@@@|%{_datadir}|g" \
%{buildroot}%{sysconfigdir}/%{name}
%pre
# create logstash group
@ -67,8 +96,8 @@ fi
# create logstash user
if ! getent passwd logstash >/dev/null; then
useradd -r -g logstash -d %{base_install_dir} \
-s /sbin/nologin -c "Logstash" logstash
useradd -r -g logstash -d %{_javadir}/%{name} \
-s /sbin/nologin -c "You know, for search" logstash
fi
%post
@ -85,28 +114,65 @@ rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%dir %{base_install_dir}
%dir %{base_install_dir}/plugins
%dir %{_sysconfdir}/%{name}/patterns
# JAR file
%{_javadir}/%{name}.jar
%{_sysconfdir}/rc.d/init.d/logstash
%{_sysconfdir}/logrotate.d/logstash
# Config
%config(noreplace) %{confdir}/
%{base_install_dir}/logstash.jar
# Wrapper script
%{bindir}/*
%config(noreplace) %{_sysconfdir}/sysconfig/logstash
%defattr(-,logstash,logstash,-)
%{_localstatedir}/run/logstash
%{base_install_dir}/tmp
%dir %{_localstatedir}/log/logstash
# Logrotate
%config(noreplace) %{_sysconfdir}/logrotate.d/%{name}
# Sysconfig and init
%{_initddir}/%{name}
%config(noreplace) %{sysconfigdir}/*
%defattr(-,%{name},%{name},-)
%dir %{logdir}/
%dir %{piddir}/
%changelog
* Sun Oct 27 2013 <sbagmeijer@ulyaoth.asia> - 1.2.2-2
- Fixed the bogus date warning
* Wed Oct 23 2013 <sjir@basefarm.no> - 1.2.2-1
- Update logstash version to 1.2.2-1
* Fri Sep 27 2013 <sbagmeijer@ulyaoth.asia> - 1.2.1-1
- Building for Fedora 18, 19 and 20-alpha.
- Added Source5 for logstash.conf
- Fixed the BuildArch so it can be build for i386
* Mon Sep 16 2013 <sjir@basefarm.se> - 1.2.1
- Updated version to the new 1.2.1
- Removed everything related to plugins as it no longer works.
* Wed Sep 04 2013 <sjir@basefarm.se> - 1.2.0
- Updated version to the new 1.2.0.
- Fixed a problem with the init.d script not working correctly.
* Fri Jun 14 2013 <sjir@basefarm.se> - 1.1.13-1
- Updated version to the new 1.1.13-1 and fixed some minor issues with directory structure.
* Mon May 6 2013 <sjir@basefarm.se> - 1.1.10-3
- Changed from logstash flatjar to the monolith as flatjar is not working correctly yet.
* Fri Apr 19 2013 <sjir@basefarm.se> - 1.1.10-2
- Fixed a bug
* Fri Apr 19 2013 <sjir@basefarm.se> - 1.1.10-1
- Added fixes to support RHEL6
- Update logstash version to 1.1.10
* Sun Mar 17 2013 Richard Pijnenburg <richard@ispavailability.com> - 1.1.9-2
- Update init script
- Create patterns dir in correct place
* Sat Feb 1 2013 Richard Pijnenburg <richard@ispavailability.com> - 1.1.9-1
* Fri Feb 1 2013 Richard Pijnenburg <richard@ispavailability.com> - 1.1.9-1
- Update to latest stable release.
- New init script