Skip to content

Instantly share code, notes, and snippets.

@samueljon
Forked from slojo404/logstash RPM spec
Created October 13, 2012 18:51
Show Gist options
  • Save samueljon/3885739 to your computer and use it in GitHub Desktop.
Save samueljon/3885739 to your computer and use it in GitHub Desktop.
logstash monolithic init script and spec file for CentOS / RedHat
Name: logstash
Version: 1.1.0
Release: 1%{?dist}
Summary: logstash is a tool for managing events and logs
Group: System/Logging
License: ASL 2.0
URL: http://logstash.net/
Source0: http://semicomplete.com/files/logstash/logstash-%{version}-monolithic.jar
Source1: logstash
Source2: logstash.conf
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildArch: noarch
Requires: java
Requires: grok
%description
logstash is a tool for managing events and logs. You can use it to collect logs, parse them, and store them for later use (like, for searching). Speaking of searching, logstash comes with a web interface for searching and drilling into all of your logs.
It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way.
%prep
%build
%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT/opt/%{name} $RPM_BUILD_ROOT/%{_sysconfdir}/rc.d/init.d
install %{SOURCE0} $RPM_BUILD_ROOT/opt/%{name}
install -m 755 %{SOURCE1} $RPM_BUILD_ROOT/%{_sysconfdir}/rc.d/init.d/%{name}
install %{SOURCE2} $RPM_BUILD_ROOT/%{_sysconfdir}
ln -s /opt/%{name}/%{name}-%{version}-monolithic.jar $RPM_BUILD_ROOT/opt/%{name}/%{name}-monolithic.jar
%clean
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root,-)
%config %{_sysconfdir}/logstash.conf
/opt/%{name}/%{name}-%{version}-monolithic.jar
/opt/%{name}/%{name}-monolithic.jar
%{_sysconfdir}/rc.d/init.d/%{name}
%changelog
#! /bin/sh
#
# /etc/rc.d/init.d/logstash
#
# Starts Logstash as a daemon
#
# chkconfig: 2345 20 80
# description: Starts Logstash as a daemon
# pidfile: /var/run/logstash-agent.pid
### 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.
# Author: [email protected], modified by https://github.com/paul-at
### END INIT INFO
# Amount of memory for Java
JAVAMEM=256M
# Location of logstash files
LOCATION=/opt/logstash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
DESC="Logstash Daemon"
NAME=java
DAEMON=`which java`
CONFIG_DIR=/etc/logstash.conf
LOGFILE="/var/log/logstash.log"
PATTERNSPATH="/opt/logstash/patterns"
JARNAME=logstash-monolithic.jar
ARGS="-Xmx$JAVAMEM -Xms$JAVAMEM -jar ${JARNAME} agent --config ${CONFIG_DIR} --log ${LOGFILE} --grok-patterns-path ${PATTERNSPATH}"
SCRIPTNAME=/etc/init.d/logstash
base=logstash
# Exit if the package is not installed
if [ ! -x "$DAEMON" ]; then
{
echo "Couldn't find $DAEMON"
exit 99
}
fi
. /etc/init.d/functions
#
# Function that starts the daemon/service
#
do_start()
{
cd $LOCATION && \
($DAEMON $ARGS &) \
&& success || failure
}
#
# Function that stops the daemon/service
#
do_stop()
{
pid=`ps auxww | grep 'logstash.*monolithic' | grep java | awk '{print $2}'`
if checkpid $pid 2>&1; then
# TERM first, then KILL if not dead
kill -TERM $pid >/dev/null 2>&1
usleep 100000
if checkpid $pid && sleep 1 &&
checkpid $pid && sleep $delay &&
checkpid $pid ; then
kill -KILL $pid >/dev/null 2>&1
usleep 100000
fi
fi
checkpid $pid
RC=$?
[ "$RC" -eq 0 ] && failure $"$base shutdown" || success $"$base shutdown"
}
case "$1" in
start)
echo -n "Starting $DESC: "
do_start
touch /var/lock/subsys/$JARNAME
;;
stop)
echo -n "Stopping $DESC: "
do_stop
rm /var/lock/subsys/$JARNAME
;;
restart|reload)
echo -n "Restarting $DESC: "
do_stop
do_start
;;
status)
status -p $PID
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2
exit 3
;;
esac
echo
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment