view logstash.rc @ 24:0f249d38da21

jruby.spec needs /usr/share to match fedora jrudy location
author Carl Byington <carl@five-ten-sg.com>
date Fri, 19 Apr 2013 17:48:29 -0700
parents 729f36e68da8
children d058481276aa
line wrap: on
line source

#!/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

. /etc/sysconfig/logstash

export HOME=/var/lib/logstash
DESC="Logstash Daemon"
JAVA=$(which java)
CONFIGFILE=/etc/logstash/logstash.conf
LOGFILE=/var/log/logstash/logstash.log
JARNAME=/usr/share/java/logstash.jar
ARGS="$JAVAARGS -jar $JARNAME agent --config $CONFIGFILE --log $LOGFILE $AGENTARGS -- web $WEBARGS"
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=$(
    exec sudo -u logstash /bin/bash - <<EOF
        $JAVA $ARGS >&2 &
        echo \$!
EOF
    )
    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)
    echo -n "$base "
    status -p $PIDFILE
    ;;
  *)
    echo "Usage: service $base {start|stop|status|restart}" >&2
    exit 3
    ;;
esac

echo
exit 0