Created
May 24, 2011 14:14
-
-
Save vvuksan/988765 to your computer and use it in GitHub Desktop.
Logstash Init script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# | |
# Logstash Start/Stop logstash | |
# | |
# chkconfig: 345 99 99 | |
# description: Logstash | |
# processname: logstash | |
logstash_bin="/usr/java/latest/bin/java -jar /opt/logstash/logstash.jar" | |
logstash_conf="/etc/logstash/logstash.conf" | |
logstash_log="/var/log/logstash/logstash.log" | |
NICE_LEVEL="-n 19" | |
find_logstash_process () { | |
PIDTEMP=`ps ux | grep logstash | grep java | awk '{ print $2 }'` | |
# Pid not found | |
if [ "x$PIDTEMP" = "x" ]; then | |
PID=-1 | |
else | |
PID=$PIDTEMP | |
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} agent -f /etc/logstash/agent.conf > ${logstash_log} & | |
} | |
stop () { | |
find_logstash_process | |
if [ $PID -ne -1 ]; then | |
kill $PID | |
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 | |
exit 0 | |
else | |
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