Mercurial > logstash
diff logstash.rc @ 0:df4952a2fb06
initial version
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 01 Mar 2013 14:58:09 -0800 |
parents | |
children | 796ac0b50dbf |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/logstash.rc Fri Mar 01 14:58:09 2013 -0800 @@ -0,0 +1,96 @@ +#!/bin/bash +# +# /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.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. +# Modified originally from https://gist.github.com/2228905#file_logstash.sh + +### END INIT INFO + +# Amount of memory for Java +#JAVAMEM=256M + +export HOME=/var/lib/logstash +DESC="Logstash Daemon" +JAVA=$(which java) +CONFIGFILE=/etc/logstash/logstash.conf +LOGFILE=/var/log/logstash/logstash.log +JARNAME=/usr/local/bin/logstash.jar +ARGS="-jar ${JARNAME} agent -vvv --config ${CONFIGFILE} --log ${LOGFILE} -- web --backend elasticsearch://127.0.0.1/?local" +SCRIPTNAME=/etc/rc.d/init.d/logstash +PIDFILE=/var/run/logstash.pid +base=logstash + +# Exit if java is not installed +if [ ! -x "$JAVA" ]; then + echo "Couldn't find $JAVA" + exit 99 +fi + +. /etc/init.d/functions + +# +# Function that starts the daemon/service +# +do_start() { + cd $HOME + pid=$(su logstash -c 'echo -e "'"$JAVA $ARGS"' </dev/null >'"$LOGFILE"' 2>&1 & \n echo \$!" | bash') + echo $pid >$PIDFILE + [ -n "$pid" ] && success $"$base startup" || failure $"$base startup" +} + + +# +# Function that stops the daemon/service +# +do_stop() { + killproc -p $PIDFILE logstash +} + + +case "$1" in + start) + echo -n "Starting $DESC: " + do_start + touch /var/lock/subsys/$base + ;; + stop) + echo -n "Stopping $DESC: " + do_stop + rm /var/lock/subsys/$base 2>/dev/null + rm $PIDFILE 2>/dev/null + ;; + restart) + echo -n "Restarting $DESC: " + do_stop + do_start + ;; + reload) + echo -n "Reloading $DESC: " + pid=$(cat $PIDFILE) + [ -n "$pid" ] && pkill -HUP -u logstash -P $pid + ;; + status) + status -p $PIDFILE + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|status|restart}" >&2 + exit 3 + ;; +esac + +echo +exit 0