Skip to content

Instantly share code, notes, and snippets.

@kjoconnor
Created June 3, 2011 22:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kjoconnor/1007305 to your computer and use it in GitHub Desktop.
Save kjoconnor/1007305 to your computer and use it in GitHub Desktop.
Logstash Web init script
#! /bin/sh
#
# Logstash Start/Stop logstash
#
# chkconfig: 345 99 99
# description: Logstash
# processname: logstash
logstash_bin="java -Djava.net.preferIPv4Stack=true -jar /opt/logstash/logstash-1.0.11pre-monolithic.jar"
logstash_log="/opt/logstash/logstash-web.log"
NICE_LEVEL="-n 19"
PID_FILE="/opt/logstash/logstash-web.pid"
find_logstash_process () {
if [ -f $PID_FILE ]; then
PID=`cat $PID_FILE`
else
PIDTEMP=`ps ux | grep logstash | grep java | grep web | awk '{ print $2 }'`
# Pid not found
if [ "x$PIDTEMP" = "x" ]; then
PID=-1
else
PID=$PIDTEMP
# Recompose PID file, not sure if there's a better way of handling this
echo "Warning: no PID file found, replacing"
echo $PID > $PID_FILE
fi
fi
}
start () {
LOG_DIR=`dirname ${logstash_log}`
if [ ! -d $LOG_DIR ]; then
echo "Log dir ${LOG_DIR} doesn't exist. Creating"
mkdir $LOG_DIR
fi
nohup nice ${NICE_LEVEL} ${logstash_bin} web > ${logstash_log} &
PID=`ps ux | grep logstash | grep java | grep web | awk '{ print $2}'`
if [ "x$PID" = "x" ]; then
PID=-1
fi
if [ $PID -eq -1 ]; then
echo "Logstash failed to start."
exit 1
else
echo $PID > $PID_FILE
echo "Started successfully, PID $PID"
exit 0
fi
}
stop () {
find_logstash_process
if [ "$PID" -ne "-1" ]; then
kill $PID
if [ "$?" -eq "0" ]; then
echo "Logstash web stopped successfully."
rm -f $PID_FILE
exit 0
else
echo "Logstash was not stopped."
fi
else
echo "Couldn't find Logstash PID, is it running?"
fi
}
case $1 in
start)
start
;;
stop)
stop
exit 0
;;
reload)
stop
start
;;
restart)
stop
start
;;
status)
find_logstash_process
if [ $PID -gt 0 ]; then
if [ -d /proc/$PID ]; then
echo "Running, PID $PID"
else
echo "Found PID file, but process does not exist. Removing stale PID."
rm -f $PID_FILE
fi
else
echo "Not running."
exit 1
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
RETVAL=1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment