Skip to content

Instantly share code, notes, and snippets.

@lboynton
Created April 18, 2012 14:27
Show Gist options
  • Save lboynton/2413937 to your computer and use it in GitHub Desktop.
Save lboynton/2413937 to your computer and use it in GitHub Desktop.
Logstash init script
#! /bin/sh
### BEGIN INIT INFO
# Provides: logstash-shipper
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
mode="shipper"
logstash_bin="/usr/bin/java -jar /usr/local/bin/logstash/logstash.jar"
logstash_conf="/etc/logstash/logstash.conf"
logstash_log="/var/log/logstash.log"
NICE_LEVEL="-n 19"
find_logstash_process () {
PIDTEMP=`ps ux | grep logstash | grep java | grep $mode | awk '{ print $2 }'`
# Pid not found
if [ "x$PIDTEMP" = "x" ]; then
PID=-1
else
PID=$PIDTEMP
fi
}
start () {
find_logstash_process
if [ $PID -gt 0 ]; then
echo "logstash $mode is already running"
exit 0
fi
LOG_DIR=`dirname ${logstash_log}`
if [ ! -d $LOG_DIR ]; then
echo "Log dir ${LOG_DIR} doesn't exist. Creating"
mkdir -p $LOG_DIR
fi
nohup nice ${NICE_LEVEL} ${logstash_bin} agent -f "/etc/logstash/logstash.conf" -l ${logstash_log} > ${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
echo "Logstash $mode is running"
exit 0
else
echo "Logstash $mode is 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