[packages/logstash] add initscript

glen glen at pld-linux.org
Sun Mar 17 20:08:49 CET 2013


commit 09dd170ad3d64737c73764bdb195c6bc46ff4f53
Author: Elan Ruusamäe <glen at delfi.ee>
Date:   Sun Mar 17 20:27:45 2013 +0200

    add initscript

 logstash-agent.init      | 125 +++++++++++++++++++++++++++++++++++++++++++++++
 logstash-agent.sysconfig |  14 ++++++
 logstash.spec            |  28 +++++++++--
 3 files changed, 164 insertions(+), 3 deletions(-)
---
diff --git a/logstash.spec b/logstash.spec
index d678769..aaccb33 100644
--- a/logstash.spec
+++ b/logstash.spec
@@ -10,11 +10,18 @@ License:	Apache v2.0
 Group:		Daemons
 Source0:	http://logstash.objects.dreamhost.com/release/%{name}-%{version}-monolithic.jar
 # Source0-md5:	70addd3ccd37e796f473fe5647c31126
+Source1:	%{name}-agent.init
+Source2:	%{name}-agent.sysconfig
 URL:		http://www.logstash.net/
+BuildRequires:	rpmbuild(macros) >= 1.228
+Requires(post,preun):	/sbin/chkconfig
 Requires:	jre
+Requires:	rc-scripts
 BuildArch:	noarch
 BuildRoot:	%{tmpdir}/%{name}-%{version}-root-%(id -u -n)
 
+%define	no_install_post_check_tmpfiles 1
+
 %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
@@ -26,17 +33,32 @@ for searching and drilling into all of your logs.
 
 %install
 rm -rf $RPM_BUILD_ROOT
-install -d $RPM_BUILD_ROOT{%{_sysconfdir}/%{name}/patterns,%{_datadir}/%{name},/var/{lib,log}/logstash}
+install -d $RPM_BUILD_ROOT{%{_sysconfdir}/%{name}/patterns,%{_datadir}/%{name},/var/{lib,log,run}/logstash}
 cp -p %{SOURCE0} $RPM_BUILD_ROOT%{_datadir}/%{name}/logstash-monolithic.jar
+install -Dp %{SOURCE1} $RPM_BUILD_ROOT/etc/rc.d/init.d/logstash-agent
+install -Dp %{SOURCE2} $RPM_BUILD_ROOT/etc/sysconfig/logstash-agent
 
 %clean
 rm -rf $RPM_BUILD_ROOT
 
+%post
+/sbin/chkconfig --add logstash-agent
+%service logstash-agent restart
+
+%preun
+if [ "$1" = "0" ]; then
+	%service -q logstash-agent stop
+	/sbin/chkconfig --del logstash-agent
+fi
+
 %files
 %defattr(644,root,root,755)
 %dir %attr(750,logstash,logstash) %{_sysconfdir}/%{name}
 %dir %attr(750,logstash,logstash) %{_sysconfdir}/%{name}/patterns
+%config(noreplace) %verify(not md5 mtime size) %attr(640,root,root) /etc/sysconfig/logstash-agent
+%attr(754,root,root) /etc/rc.d/init.d/logstash-agent
 %dir %{_datadir}/%{name}
 %{_datadir}/%{name}/%{name}-monolithic.jar
-%dir %attr(750,logstash,logstash) /var/lib/%{name}
-%dir %attr(750,logstash,logstash) /var/log/%{name}
+%dir %attr(770,root,logstash) /var/lib/%{name}
+%dir %attr(770,root,logstash) /var/log/%{name}
+%dir %attr(770,root,logstash) /var/run/%{name}
diff --git a/logstash-agent.init b/logstash-agent.init
new file mode 100755
index 0000000..8d1b334
--- /dev/null
+++ b/logstash-agent.init
@@ -0,0 +1,125 @@
+#!/bin/sh
+#
+# logstash-agent	Starts logstash services
+#
+# chkconfig:	2345 80 20
+#
+# description:	Logstash services
+#
+# processname:	logstash-agent
+# config:
+# pidfile:		/var/run/logstash/agent.pid
+
+# Source function library
+. /etc/rc.d/init.d/functions
+
+# Get network config
+. /etc/sysconfig/network
+
+# Check that networking is up.
+if is_yes "${NETWORKING}"; then
+	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
+		msg_network_down "logstash agent"
+		exit 1
+	fi
+else
+	exit 0
+fi
+
+# Set defaults
+SERVICE=agent
+USER=logstash
+GROUP=logstash
+JARFILE=/usr/share/logstash/logstash-monolithic.jar
+CONFIG=/etc/logstash/$SERVICE.conf
+PIDDIR=/var/run/logstash
+PIDFILE=$PIDDIR/$SERVICE.pid
+LOGDIR=/var/log/logstash
+LOGFILE=$LOGDIR/$SERVICE.log
+JAVA_MEM_MIN="128M"
+JAVA_MEM_MAX="256M"
+START_STOP_OPTS=""
+ARGS=""
+TRIES=5
+
+# Get service config - may override defaults
+[ -f /etc/sysconfig/logstash-agent ] && . /etc/sysconfig/logstash-agent
+
+JAVA_OPTS="-Xmx$JAVA_MEM_MAX -Xms$JAVA_MEM_MIN $JAVA_OPTS"
+
+start() {
+	# Check if the service is already running?
+	if [ -f /var/lock/subsys/logstash-agent ]; then
+		msg_already_running "logstash agent"
+		return
+	fi
+
+	msg_starting "logstash agent"
+
+	DAEMON=$(which java)
+	DAEMON_OPTS="$JAVA_OPTS -jar $JARFILE $SERVICE -f $CONFIG -l $LOGFILE $ARGS"
+
+	$DAEMON $DAEMON_OPTS &
+	RETVAL=$?
+	pid=$!
+	if [ $RETVAL -eq 0 ]; then
+		ok
+		echo $pid > $PIDFILE
+		touch /var/lock/subsys/logstash-agent
+	else
+		fail
+	fi
+}
+
+stop() {
+	if [ ! -f /var/lock/subsys/logstash-agent ]; then
+		msg_not_running "logstash agent"
+		return
+	fi
+
+	# Stop daemons.
+	msg_stopping "logstash agent"
+	killproc --pidfile $PIDFILE java -TERM
+	rm -f /var/lock/subsys/logstash-agent
+}
+
+condrestart() {
+	if [ ! -f /var/lock/subsys/logstash-agent ]; then
+		msg_not_running "logstash agent"
+		RETVAL=$1
+		return
+	fi
+
+	stop
+	start
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+  start)
+	start
+	;;
+  stop)
+	stop
+	;;
+  restart)
+	stop
+	start
+	;;
+  try-restart)
+	condrestart 0
+	;;
+  force-reload)
+	condrestart 7
+	;;
+  status)
+	status --pidfile $PIDFILE logstash-agent java
+	RETVAL=$?
+	;;
+  *)
+	msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
+	exit 3
+esac
+
+exit $RETVAL
diff --git a/logstash-agent.sysconfig b/logstash-agent.sysconfig
new file mode 100644
index 0000000..4d7813f
--- /dev/null
+++ b/logstash-agent.sysconfig
@@ -0,0 +1,14 @@
+# Customized settings for logstash agent
+
+#USER=logstash
+#JARFILE=/usr/share/logstash/logstash-monolitic.jar
+#CONFIG=/etc/logstash/$SERVICE.conf
+#PATTERNS=/etc/logstash/patterns
+#GROKFILE=$PATTERNS/grok-patterns
+#PLUGINS=/etc/logstash/plugins
+#LOGDIR=/var/log/logstash
+#LOGFILE=$LOGDIR/$SERVICE.log
+#JAVA_MEM_MIN="256M"
+#JAVA_MEM_MAX="256M"
+#JAVA_OPTS=""
+#ARGS=""
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/logstash.git/commitdiff/de9700ecf585b7d29b73f451c13689b4810ce675



More information about the pld-cvs-commit mailing list